我一直在使用 jQuerystop(true, true)
方法清除正在运行的动画,以便下一个立即开始。我注意到第一个参数,clearQueue
,清除整个动画队列,但第二个参数,jumpToEnd
,仅跳转到当前正在运行的动画的末尾,而不是从队列中删除的动画。有没有办法让它清晰并跳转到所有排队动画的末尾?
我最终链接了一些stop(false, true)
调用,但这只会处理 3 个排队的动画,例如。
$(this)
.stop(false, true)
.stop(false, true)
.stop(false, true)
.addClass('hover', 200);
Edit:
我最终添加了我自己的方法,stopAll
,根据 Ates Goral 的回答:
$.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);
}
Demo: http://jsfiddle.net/AB33X/ http://jsfiddle.net/AB33X/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)