编程语言
首页 > 编程语言> > javascript-调用stop时,jquery动画队列promise会发生什么

javascript-调用stop时,jquery动画队列promise会发生什么

作者:互联网

我想知道当调用.stop()函数时动画队列承诺状态会发生什么.

例如:

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

如果.stop()函数在任何时候被调用,那么较早返回的承诺会发生什么?

现在,我感觉到承诺的兑现将永远保持下去.有什么线索吗?

解决方法:

停止动画将解决承诺.

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

标签:promise,jquery-animate,javascript,jquery
来源: https://codeday.me/bug/20191101/1980386.html