gpt4 book ai didi

javascript - clearInterval - 出了点问题

转载 作者:行者123 更新时间:2023-11-28 09:46:53 25 4
gpt4 key购买 nike

看来大家对clearInterval都有一些疑问。我构建了一个 slider ,允许人们将鼠标悬停在箭头上单击。横幅也会每隔几秒钟旋转一次。我希望能够在有人单击其中一个箭头后关闭自动旋转。

这是我的代码:

$(function(){
var intvl = 0;
intvl = setInterval(heroTransitionNext, 2000);
$('.rightArrow').click(function(){
window.clearInterval(intvl);
});
});

编辑:

这是它调用的函数:

function heroTransitionNext() {
$('.HP-hero li').filter(':visible').fadeOut('normal', function () {
if ($(this).next().length != 0) {
activeZone = parseInt(activeZone) + 1;
$(this).next().fadeIn('normal', heroNavHighlight(activeZone));
} else {
activeZone = 1;
$('.HP-hero li:first-child').fadeIn('normal', heroNavHighlight(activeZone));
}
$(this).hide();
});
};

最佳答案

要停止动画,您可以使用 jquery.stop()但不确定它是否能解决您面临的问题(没有想象),但您可以尝试一下

$('.HP-hero li').stop(1,1); // or try $('.HP-hero li').stop()
window.clearInterval(intvl);

say2joeclearInterval只会阻止该函数下次调用,但不会清除当前队列(他是对的),所以在这种情况下 stop可以使用。

About Stop .

关于javascript - clearInterval - 出了点问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11678841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com