1

コールバックを受け入れるカスタム jquery 関数を作成しましたが、アニメーション関数の実行が終了したときにコールバック関数が呼び出し環境でどのように実行されるかを理解できませんでした。

ここに私のカスタム関数コードがあります

jQuery.fn.busyToggle = function (flag, marginBottom, opacity, speed, easing, callback) {
        if (flag == 1) {
            return this.stop(true).animate({ marginBottom: marginBottom, opacity: opacity }, { queue: false, duration: speed });
        }
        else {
            return this.stop(true).animate({ marginBottom: marginBottom, opacity: opacity }, { queue: false, duration: speed });
        }
    };

このように私はこの関数を呼び出しています

$('#BusyBox').busyToggle(flag,0,1,500);

アニメーション関数が呼び出し環境から終了したときにキャプチャする方法を知る必要があります。可能であれば、詳細に議論してください。ありがとう

4

2 に答える 2

1

1 つの方法は、によって提供されるコールバック関数を使用することです。.animate() もう 1 つの方法は、次のようにチェーン キューに追加することです。

jQuery.fn.busyToggle = function(flag, marginBottom, opacity, speed, easing, callback) {
    if (flag == 1) {
        return this.stop(true).animate({
            marginBottom: marginBottom,
            opacity: opacity
        }, {
            queue: false,
            duration: speed
        }).queue(callback);
    }
    else {
        return this.stop(true).animate({
            marginBottom: marginBottom,
            opacity: opacity
        }, {
            queue: false,
            duration: speed
        }).queue(callback);
    }
};​
于 2012-06-19T12:58:00.647 に答える
0

コールバックを完全なオプションに追加するだけですanimate

jQuery.fn.busyToggle = function (flag, marginBottom, opacity, speed, easing, callback) {
    ...
    this.stop(true).animate({ marginBottom: marginBottom, opacity: opacity }, { queue: false, duration: speed, complete: callback });
};

$('#BusyBox').busyToggle(flag,0,1,500, function(){ 
    // do something on complete
});
于 2012-06-19T13:06:22.170 に答える