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

我一直在使用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); 

我希望别人觉得这很有用。

jQuery 1.9引入了.finish()方法,它实现了这一点。

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

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

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

我还注意到jQuery 1.9中的.finish()方法的文档

通过设置属性$ .fx.off可以全局停止动画 
为真。 完成后,所有动画方法将立即生效 
调用时将元素设置为最终状态,而不是显示效果。

在.finish()文档页面上还有一个很好的各种方法演示。

在开始新动画之前,测试是否存在类(在hover时设置并在mouseOut动画回调中删除)。 当新动画开始时,出列。

 $("div").hover(function(){ if (!$(this).hasClass('animated')) { $(this).dequeue().stop().animate({ width: "200px" }); } }, function() { $(this).addClass('animated').animate({ width: "100px" }, "normal", "linear", function() { $(this).removeClass('animated').dequeue(); }); });