Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what happen to jquery animation queue promise when stop is called

I was wondering about what happen to an animation queue promise state when the .stop() function is called on it.

For example:

$('.my-elem')
    .stop(true, true)
    .animate({})
    .promise()
    .always(function() {
        // do something
    })

If the .stop() function get called at any point, what happen to the promise returned earlier ?

Right now, I get the feeling the promise returned just keep on pending forever. Any clue on this ?

like image 602
Simon Boudrias Avatar asked Jan 27 '26 18:01

Simon Boudrias


1 Answers

Stopping the animation resolves the promise.

//start the anim and alert 'done' on deferred resolution
$('div').animate({height: 500}, 3000).promise().done(function() {
    alert('deferred resolved');
});

//interrupt it after 1 second
setTimeout(function() { $('div').stop(); }, 1000);
like image 134
Mitya Avatar answered Jan 30 '26 06:01

Mitya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!