I need to stop the animation and instantly complete all pending animations.
stop
doesn't work:
Lets say I have animation that moves element that is on 0px
by 100px
and I use stop when it moved only 50px
. The result will be an element at 50px
. The result I want is when I interrupt the animation, even if the element is at 50px
it will instantly jump to 100px
.
How do I do that?
views:
46answers:
3
+1
A:
$.fn.stop() has the option to clear the queue and to jump to the end.
Just do something like: $('#foo').stop(true, true);
PetersenDidIt
2010-08-10 15:38:42
It doesn't work when I have multiple queued animations, it jumps only to the end of the first one and discards the rest.
Dani
2010-08-10 15:43:47
Thats because your selector is too specific. Say there are 3 divs on the page, #div-1, #div-2, #div-3. #div-1 and #div-2 are in the middle of an animation when you want to stop them so that you can animate #div-3, or whatever. To stop the queued animations you would do:$('#div-1, #div-2').stop(true, true);To stop all animations on the page, you could try:$('*').stop(true, true);
m4olivei
2010-10-08 16:28:32
A:
found this at http://forum.jquery.com/topic/stop-true-true-animation-chains-and-callbacks
(function($){
$.fn.extend({
hardStop: function(){
return this.each(function(){
var e = $(this);
while (e.queue().length){
e.stop(false, true);
}
});
}
});
})(jQuery);
use it by
$("#element").hardStop();
If that doesn't work, maybe change your original code to:
$("#abc").stop().animate(...
JKirchartz
2010-08-10 15:41:37
A:
Specify manually the last state, don't be lazy. Im sure you can do it :)
$('#foo').stop(true, true);
$('#foo').css({x, '100px'});
Gabriel
2010-10-08 10:20:45