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?
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);
Edit:
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.
Chaining multiple stop(false, true)
makes sense. Instead of hard-coding a fixed number of chained calls, you could check the queue length:
while ($(this).queue().length) {
$(this).stop(false, true);
}
Demo: http://jsfiddle.net/AB33X/
jQuery 1.9 introduced the .finish() method, which achieves exactly that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With