Instantly terminate an animation queue in jQuery

I need to stop the animation and instantly complete all pending animations.
stopdoesn't work:
Let's say I have an animation that moves an element that is on 0pxby 100px, and I use stop when it only moves 50px. The result will be item c 50px. The result I want is when I interrupt the animation, even if the item is in 50px, it will instantly go to 100px.
How to do it?

+3
source share
3 answers

$. fn.stop () has the ability to clear the queue and go to the end.

- : $('#foo').stop(true, true);

+1

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);

$("#element").hardStop();

, , :

$("#abc").stop().animate(...
0

Specify manually the last state, do not be lazy. I'm sure you can do it :)

$('#foo').stop(true, true);
$('#foo').css({x, '100px'});
0
source

Source: https://habr.com/ru/post/1758947/


All Articles