简体   繁体   English

动画完成后回调函数

[英]callback to functions after animation completed

here is my small problem: 这是我的小问题:

I want to call to functions after animation completed. 我想在动画完成后调用函数。 I can one with this example. 我可以用这个例子。 But I need to call one more. 但我还需要再打电话。

Sample code 示例代码

$('.content').animate({
    left: '100'}, {
    duration: 500,
    complete: onComplete /* function is passed as a variable, not called directly , 
                             its doesn't work like : onComplete()*/
});

I have already tried following things and I don't get it. 我已经尝试过以下事情但我没有得到它。 how to fix it. 如何解决它。

try 1. complete:onComplete, secondonCompletefn
try 2. complete:onComplete, 
       complete:secondonCompletefn

Thank you. 谢谢。

$('.content').animate({
    left: '100'}, {
    duration: 500,
    complete: function(){
        onComplete();
        secondonCompletefn();
    }
});

You should be able to pass the callback as a third parameter(second is the duration) to the animate function, like: 您应该能够将回调作为第三个参数(第二个是持续时间)传递给animate函数,例如:

$('.content').animate({
    left: '100'}
}, 500, function() {
 onComplete();
});

Try this 尝试这个

function foo(){
        onComplete();
        secondonCompletefn();
}
$('.content').animate({
    left: '100'}, {
    duration: 500                         
}).promise().done(foo);// this will animate and then call the function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM