我有一個內容滑塊腳本中的現有功能,它爲下一張幻燈片設置超時動畫。我想停止mouseover上的動畫(我評論了我對腳本的補充)。我究竟做錯了什麼?謝謝你的幫助。setTimeout,clearTimeout jQuery
function autoSlide() {
if (navClicks == 0 || !settings.autoSlideStopWhenClicked) {
if (currentPanel == panelCount) {
var offset = 0;
currentPanel = 1;
} else {
var offset = - (panelWidth*currentPanel);
currentPanel += 1;
};
alterPanelHeight(currentPanel - 1);
// Switch the current tab:
slider.siblings('.coda-nav').find('a').removeClass('current').parents('ul').find('li:eq(' + (currentPanel - 1) + ') a').addClass('current');
// Slide:
$('.panel-container', slider).animate({ marginLeft: offset }, settings.slideEaseDuration, settings.slideEaseFunction);
setTimeout(autoSlide,settings.autoSlideInterval);
// this is my addition to try to stop the animation:
$('.panel-container', slider).mouseover(function(){
//alert("hi");
clearTimeout(autoSlide);
}).mouseleave(function(){
setTimeout(autoSlide,settings.autoSlideInterval);
});
// end of my addition
};
};
有什麼問題? – SLaks
它不起作用... – user803592
如果它仍然不能正常工作(當您真正看到發生了什麼時,它會更容易),您可以發佈[jsFiddle](http://jsfiddle.net)演示。 – kapa