jQuery滑块不会立即停止

问题描述:

我想知道为什么我的jQuery滑块不会立即停止事件后:mouseover。有一个延迟,有人能帮我解决这个问题吗? 这里有我的代码:https://jsfiddle.net/jrswchkp/1/jQuery滑块不会立即停止

$(function() { 

    var $clientcarousel = $('#clients-list'); 
    var clients = $clientcarousel.children().length; 
    var clientwidth = (clients * 400); // 140px width for each client item 
    $clientcarousel.css('width', clientwidth); 

    var rotating = true; 
    var clientspeed = 0; 
    var seeclients = setInterval(rotateClients, clientspeed); 


    function rotateClients() { 
    if (rotating != false) { 
     var $first = $('#clients-list li:first'); 
     $first.animate({'margin-left': '-220px'}, 5000, "linear", function() { 
     $first.remove().css({'margin-left': '0px'}); 
     $('#clients-list li:last').after($first); 
     }); 
    } else { 
    $('#clients-list li').stop(); 
    } 
    } 

    $(document).on({ 
    mouseover: function(){ 
     rotating = false; // turn off rotation when hovering 
    }, 
    mouseleave: function(){ 
     rotating = true; 
    } 
    }, '.clients'); 

}); 

您需要确保您清除队列当您运行.stop()

else { 
    $('#clients-list li').stop(true, false); 
} 

您可以了解更多关于.stop()here

这里的JSFiddle

+0

我还有一个问题 - 立即开始呢?是否有任何功能允许回滑? –

+0

你必须创建你自己的功能。 JQuery中没有任何东西让你暂停和恢复动画。但有像[这一个]插件(http://tobia.github.io/Pause/)。 –

+0

谢谢!你能给我建议如何将这个应用到我的代码?它看起来像我是js jquery dummy –