0

実際には、アニメーションの完了後にコールバック関数が呼び出されます

(selector).animate({styles},speed,easing,callback)

アニメーションの開始前にコールバック関数を呼び出すにはどうすればよいですか?

または、アニメーションがその間に実行されているときに、このようにコールバック関数を呼び出すにはどうすればよいですか?

4

2 に答える 2

1

関数の場合callbackは、前に呼び出すだけですanimate

callback();
(selector).animate({styles},speed,easing,callback)
于 2013-09-11T06:48:09.293 に答える
0
function animate(preCallback, postCallback) {

    // Create var to hold animating object if you want to use deffereds
    var animation;

    // Animation is about to start run preCallback()
    // If you don't want the animation to start until this is complete
    // You should look at returning a deffered object from the callback
    // or using another callback inside, warning : this can get messy.
    preCallback instanceof Function && preCallback();

    // Start the animation
    animation = $('#animation').animate({styles}, speed, easing, function() {
        // Once animation is finished run finished callback
        postCallback instanceof Function && postCallback();
    });

    // Alternative Return animation as deffered so further 
    // complete callbacks can be chained to it with .done()
    return $.when(animation);
}

animate(function() {
    // preCallback code, this will NOT stop animation from starting
    // before it is complete without further logic
}, function() { 
    // postCallback code
}).done(function() {
    // further callback using deffered object
});

注として、preCallbackこのコードを実行し、完了したらそこから animate を呼び出して、この機能を追加する必要をまったくなくす方がよいでしょう。

于 2013-09-11T06:53:05.237 に答える