用box固定长宽实现图片自动轮播js代码


Posted in Javascript onJune 09, 2014

这个小DEMO,主要用box固定长宽用于显示图片,将图片放入imagebox中,连接起来,每次换图片则将imagebox的style属性的margin-left改动,能形成轮播的效果。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>无标题文档</title> 
<style> 
.box { 
width: 900px; 
height: 350px; 
margin: 20px; 
overflow: hidden; 
margin:0 auto; 
} 
.imagebox { 
width: 3600px; 
height: 350px; 
-webkit-transition: all 1s ease-in-out; 
-moz-transition: all 1s ease-in-out; 
-o-transition: all 1s ease-in-out; 
transition: all 1s ease-in-out; 
} 
.imagebox img { 
width: 900px; 
float: left; 
height: 350px; 
} 
</style> 
</head> <body> 
<div class="box"> 
<div id="ImageBox" class="imagebox"> 
<img class="trans_image" src="images/图片点击轮转/image-53.jpg" /> 
<img class="trans_image" src="images/图片点击轮转/image-54.jpg"/> 
<img class="trans_image" src="images/图片点击轮转/image-55.jpg"/> 
<img class="trans_image" src="images/图片点击轮转/image-56.jpg"/> 
</div> 
</div> 
<div> 
<input type="button" value="left" onclick="turnleft()"/> 
<input type="button" value="right" onclick="turnright()"/> 
</div> 
<script language="javascript"> 
var int=setInterval("change()",3*1000); 
var a=document.getElementById("ImageBox"); 
var i=1; 
function change(){ 
if(i==4){ 
i=0; 
} 
i=i+1; 
a.style.marginLeft=(1-i)*900+"px"; 
} 
function stopchange(){clearInterval(int);} 
function startchange(){int=setInterval("change()",2*1000);} 
a.onmouseover=function(){clearInterval(int);} 
a.onmouseout=function() {int=setInterval("change()",2*1000);} 
function turnleft(){ 
stopchange(); 
i=i+1; 
a.style.marginLeft=(1-i)*900+"px"; 
if(i==4){ 
i=0; 
} 
startchange(); 
} 
function turnright(){ 
stopchange(); 
if(i>1){ 
a.style.marginLeft=(2-i)*900+"px"; 
i=i-1; 
}else{ 
a.style.marginLeft=-3*900+"px"; 
i=4; 
} 
startchange(); 
} 
</script> 
</body> 
</html>
Javascript 相关文章推荐
防止xss和sql注入:JS特殊字符过滤正则
Apr 18 Javascript
js对象转json数组的简单实现案例
Feb 28 Javascript
javascript+HTML5的canvas实现七夕情人节3D玫瑰花效果代码
Aug 04 Javascript
D3.js中data(), enter() 和 exit()的问题详解
Aug 17 Javascript
14款经典网页图片和文字特效的jQuery插件-前端开发必备
Aug 25 Javascript
基于jQuery实现的扇形定时器附源码下载
Oct 20 Javascript
BootstrapValidator不触发校验的实现代码
Sep 28 Javascript
在点击div中的p时,如何阻止事件冒泡
Feb 07 Javascript
从零开始学习Node.js系列教程六:EventEmitter发送和接收事件的方法示例
Apr 13 Javascript
php 解压zip压缩包内容到指定目录的实例
Jan 23 Javascript
Node.js中你不可不精的Stream(流)
Jun 08 Javascript
js计算两个日期间的天数月的实例代码
Sep 20 Javascript
jQuery实现的Div窗口震动特效
Jun 09 #Javascript
js动态创建标签示例代码
Jun 09 #Javascript
jquery中 $.expr使用实例介绍
Jun 09 #Javascript
jQuery select表单提交省市区城市三级联动核心代码
Jun 09 #Javascript
javascript控制在光标位置插入文字适合表情的插入
Jun 09 #Javascript
js判断元素是否隐藏的方法
Jun 09 #Javascript
jQery使网页在显示器上居中显示适用于任何分辨率
Jun 09 #Javascript
You might like
php 远程图片保存到本地的函数类
2008/12/08 PHP
php获取QQ头像并显示的方法
2014/12/23 PHP
php字符串替换函数substr_replace()用法实例
2015/03/17 PHP
PHP实现图片自动清理的方法
2015/07/08 PHP
PHP策略模式定义与用法示例
2017/07/27 PHP
我遇到的参数传递中 双引号单引号嵌套问题
2010/02/11 Javascript
javascript实现无缝上下滚动特效
2015/12/16 Javascript
JS获取及验证开始结束日期的方法
2016/08/20 Javascript
node.js版本管理工具n无效的原理和解决方法
2016/11/24 Javascript
微信小程序 css使用技巧总结
2017/01/09 Javascript
详解Vue 全局引入bass.scss 处理方案
2018/03/26 Javascript
浅谈Vue.js 中的 v-on 事件指令的使用
2018/11/25 Javascript
深入理解令牌认证机制(token)
2019/08/22 Javascript
javascript实现异形滚动轮播
2019/11/28 Javascript
JavaScript实现联动菜单特效
2020/01/07 Javascript
python实现自动登录人人网并采集信息的方法
2015/06/28 Python
python字符类型的一些方法小结
2016/05/16 Python
python 打印出所有的对象/模块的属性(实例代码)
2016/09/11 Python
Python列表list内建函数用法实例分析【insert、remove、index、pop等】
2017/07/24 Python
Python中协程用法代码详解
2018/02/10 Python
python实现支付宝当面付(扫码支付)功能
2018/05/30 Python
解决python xlrd无法读取excel文件的问题
2018/12/25 Python
对python操作kafka写入json数据的简单demo分享
2018/12/27 Python
python实现将多个文件分配到多个文件夹的方法
2019/01/07 Python
python获取Pandas列名的几种方法
2019/08/07 Python
python scipy卷积运算的实现方法
2019/09/16 Python
Appium+Python实现简单的自动化登录测试的实现
2021/01/26 Python
结婚典礼证婚词
2014/01/11 职场文书
保护母亲河倡议书
2014/04/14 职场文书
促销活动总结范文
2014/04/30 职场文书
致百米运动员广播稿5篇
2014/10/13 职场文书
工伤认定行政答辩状
2015/05/22 职场文书
农村老人去世追悼词
2015/06/23 职场文书
暑假打工感想
2015/08/07 职场文书
redis requires ruby version2.2.2的解决方案
2021/07/15 Redis
Z-Order加速Hudi大规模数据集方案分析
2022/03/31 Servers