标签:timer class pad javascrip int html fun 作者 ons
从 作者:饥人谷_范悦 那看到的 链接:[www.jianshu.com/p/5c7c427eb557](http://www.jianshu.com/p/5c7c427eb557)
个人缩减了下,如下:
-------------------------------------------------
css:
*{ padding:0; margin:0; } li{ list-style:none; float:left; } .content{ width:600px; height:270px; margin:100px auto; } .content-box{ width:480px; height:270px; margin:0 auto; position:relative; overflow:hidden; } ul{ width:2400px; overflow:hidden; position:absolute; left: -480px; } li img{ width:480px; height: 270px; }
------------------------------------
html:
<div class="content"> <div class="content-box"> <ul> <li>![](https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1503574592707&di=a3d3ae19930d2c453ec58728e4d6a69a&imgtype=0&src=http%3A%2F%2Fimg.tuku.cn%2Ffile_big%2F201504%2F6fb5de53c5ef451980da0632d6b6b83a.jpg)</li>//图3 <li>![](https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1503574592707&di=50cb6b3fc2f467b197a42e7fa276d17f&imgtype=0&src=http%3A%2F%2Fimg.tuku.cn%2Ffile_big%2F201506%2F5c7a4b9402034d778d3d8886199aebdb.jpg)</li>//图1 <li>![](https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1503574592707&di=d133c2777c2e04c404663e00a3fd49cb&imgtype=0&src=http%3A%2F%2Fimgstore.cdn.sogou.com%2Fapp%2Fa%2F100540002%2F673510.jpg)</li>//图2 <li>![](https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1503574592707&di=a3d3ae19930d2c453ec58728e4d6a69a&imgtype=0&src=http%3A%2F%2Fimg.tuku.cn%2Ffile_big%2F201504%2F6fb5de53c5ef451980da0632d6b6b83a.jpg)</li>//图3 <li>![](https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1503574592707&di=50cb6b3fc2f467b197a42e7fa276d17f&imgtype=0&src=http%3A%2F%2Fimg.tuku.cn%2Ffile_big%2F201506%2F5c7a4b9402034d778d3d8886199aebdb.jpg)</li>//图1 </ul> </div> </div>
js:
--------------------------------------------
//此处记得引入jquery cdn:<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> var n=2;//由于第一张图是实际是最后1张,是用于从最后一张到第一张过度用,所以n=2,从第二张图开始 $(document).ready(function () {//计时器,用于自动轮播 var timer=setInterval(function () { tonext(); console.log(n); },1000) } ) //从左向右运动的函数,每次调用向右前进一张图片距离,当到达第四张(也就是给观众看的第三张),则left跳回第一张(也就是和它一样的那张,不过排在开头),由于两张图片一样,可以达到无法察觉的效果 function tonext() { $(‘ul‘).animate({left:-480*n+"px"},function () { n++; if(n==4){$(‘ul‘).css({left:0});n=1} }) }
标签:timer class pad javascrip int html fun 作者 ons
原文地址:http://www.cnblogs.com/daiski/p/7424034.html