gpt4 book ai didi

javascript - jQuery stop(true, true) 跳转到队列中所有动画的末尾

转载 作者:可可西里 更新时间:2023-11-01 02:40:33 24 4
gpt4 key购买 nike

我一直在使用 jQuery 的 stop(true, true) 方法来清除正在运行的动画,以便下一个动画立即开始。我注意到第一个参数 clearQueue 清除了整个动画队列,但第二个参数 jumpToEnd 只跳转到当前正在运行的动画的结尾,而不是那些从队列中删除。有没有办法让它清除并跳转到所有排队动画的末尾?

我最终链接了几个 stop(false, true) 调用,但这只会处理 3 个排队的动画,例如。

$(this)
.stop(false, true)
.stop(false, true)
.stop(false, true)
.addClass('hover', 200);

编辑:

根据 Ates Goral 的回答,我最终添加了自己的方法 stopAll:

$.fn.extend({ stopAll: function () {
while (this.queue().length > 0)
this.stop(false, true);
return this;
} });
$(this).stopAll().addClass('hover', 200);

我希望其他人觉得这很有用。

最佳答案

链接多个 stop(false, true) 很有意义。您可以检查队列长度,而不是硬编码固定数量的链式调用:

while ($(this).queue().length) {
$(this).stop(false, true);
}

演示:http://jsfiddle.net/AB33X/

关于javascript - jQuery stop(true, true) 跳转到队列中所有动画的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9747576/

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