4

私はjavascriptで次のメソッドを持っています:

Controller.prototype.changeScene = function (curScene, newScene) {
    sf.scene.hide(curScene);
    sf.scene.show(newScene, curScene);
    sf.scene.focus(newScene);
};

そして、別の JS クラスで:

Test.prototype.handleHide = function () {
    alert("SceneDialog.handleHide()");
    $(".screenOverlay").fadeOut("slow");
    $(".dialogBox").fadeOut("slow");
};

sf.scene.hide()メソッドを呼び出しますhandleHide。いくつhandleHideかのアニメーションがありますが、表示されていません。コントローラーは、それが完了するのを待ちません。

私は$.when(sf.scene.hide()).done()運がなかったので試しました。

助言がありますか?

4

3 に答える 3

2

jQueryキューを使用して、前のアニメーションが完了した後にのみ発生するようにキューに入れられたアニメーションのリストを保持できます。

sf.scene.hide(curScene);
sf.scene.show(newScene, curScene);
sf.scene.focus(newScene);

次のようになります。

sf.scene.hide(curScene);
sf.scene.queue(function() {
    $(this).show(newScene, curScene);
    $(this).dequeue();
});
sf.scene.queue(function() {
    sf.scene.focus(newScene);
    $(this).dequeue();
});
于 2013-07-05T15:27:13.100 に答える
2

jquery のpromise()関数を使用して、すべてのアニメーションが終了したときにコールバックを呼び出すことができます。

試してみる:

Test.prototype.handleHide = function (callback) {
    $(".screenOverlay,.dialogBox").each(
        function(i) {
            $( this ).fadeOut("slow");
        }
    );
    $(".screenOverlay,.dialogBox").promise().done(callback);
};

そして、コールバックを引数として handleHide に渡します。changeScene 関数は次のようになります。

Controller.prototype.changeScene = function (curScene, newScene) {
    sf.scene.hide(curScene, function() {
        sf.scene.show(newScene, curScene);
        sf.scene.focus(newScene);
    });
};
于 2013-07-05T15:33:04.960 に答える
1

jquery アニメーション関数を使用している場合、jquery は通常complete、関数の完了時に呼び出されるパラメーターを提供します。

使用fadeout:

$('#test').fadeOut('slow', function() {
  // fadeout is finished!! do something
});
于 2013-07-05T15:23:29.370 に答える