jQuery stop(true, true) to jump to end of all animations in queue(jQuery stop(true, true) 跳转到队列中所有动画的末尾)
问题描述
我一直在使用 jQuery 的 stop(true, true) 方法来清除正在运行的动画,以便下一个立即开始.我注意到第一个参数 clearQueue 清除了整个动画队列,但第二个参数 jumpToEnd 只跳转到当前正在运行的动画的末尾,而不是那些已从队列中删除.有没有办法让它清晰并跳转到所有排队动画的末尾?
I have been using jQuery's stop(true, true) method to clear running animations so the next one starts immediately. I noticed that the first parameter, clearQueue, clears the entire animation queue but the second parameter, jumpToEnd, only jumps to the end of the currently running animation and not the ones that were removed from the queue. Is there a way to have it clear and jump to the end of all queued animations?
我最终链接了几个 stop(false, true) 调用,但是这只会处理 3 个排队的动画,例如.
I've ended up chaining a few stop(false, true) calls instead, but this will only handle 3 queued animations, for example.
$(this)
.stop(false, true)
.stop(false, true)
.stop(false, true)
.addClass('hover', 200);
根据 Ates Goral 的回答,我最终添加了自己的方法 stopAll:
I ended up adding my own method, stopAll, as per Ates Goral's answer:
$.fn.extend({ stopAll: function () {
while (this.queue().length > 0)
this.stop(false, true);
return this;
} });
$(this).stopAll().addClass('hover', 200);
我希望其他人觉得这很有用.
I hope someone else finds this useful.
推荐答案
jQuery 1.9 引入了 .finish() 方法,正是实现了这一点.
jQuery 1.9 introduced the .finish() method, which achieves exactly that.
这篇关于jQuery stop(true, true) 跳转到队列中所有动画的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:jQuery stop(true, true) 跳转到队列中所有动画的末尾
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01
