javascript 阻止多次点击造成的轮播混乱

 1 function nextSlider(){
 2     //使用b作为开关,只有动画完成后才能进行下一次运动
 3     if(b){
 4         //如果b为真,则马上设置b为false,如果startmove的回调没有重新设置b的值,则不能继续进行下一次轮播运动;
 5         b = false;
 6         index++;
 7         startMove( oUl,{ left : -liWidth * index},function(){
 8 
 9             if (oUl.offsetLeft < -oUl.offsetWidth / 2) {
10                 oUl.style.left= -liWidth + 'px';
11                 index = 1;
12             }
13             b = true;
14         })
15         return
16     }
17 };

以前经常遇到原生javascript动画混乱,这次利用开关判断运动是否完成

原文地址:https://www.cnblogs.com/bestsamcn/p/5101758.html