2016-09-19 92 views
0

我想知道爲什麼我的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'); 

}); 

回答

1

您需要確保您清除隊列當您運行.stop()

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

您可以瞭解更多關於.stop()here

這裏的JSFiddle

+0

我還有一個問題 - 立即開始呢?是否有任何功能允許回滑? –

+0

你必須創建你自己的功能。 JQuery中沒有任何東西讓你暫停和恢復動畫。但有像[這一個]插件(http://tobia.github.io/Pause/)。 –

+0

謝謝!你能給我建議如何將這個應用到我的代碼?它看起來像我是js jquery dummy –