js无限轮播的写法

js实现轮播很简单,无限轮播也不是很难,掌握技巧就很简单了。

$(document).ready(function(){
  var x=0;
  var itime;
  var newshop=function(){
  if (x%3==1) {
    $('#shopDiv').animate({'margin-left':-1842.5},1500);
    clearTimeout(itime);
    itime=setTimeout(function(){newshop();x++;}, 6500);
  }else if(x%3==2){
    $('#shopDiv').animate({'margin-left':0},0);
    clearTimeout(itime);
    itime=setTimeout(function(){newshop();x++;}, 0);
  }else if(x%3==0){
    $('#shopDiv').animate({'margin-left':-922},1500);
    clearTimeout(itime);
  itime=setTimeout(function(){newshop();x++;}, 6500);
  }
}
itime=setTimeout(function(){newshop();x++;}, 5000);
$('#shopDiv').mouseover(function(){
clearTimeout(itime);
})
$('#shopDiv').mouseleave(function(){
clearTimeout(itime);
itime=setTimeout(function(){newshop();x++;}, 3000);
})
})

posted @ 2017-08-21 13:23  野望之风  阅读(300)  评论(0编辑  收藏  举报