1

私は2つのjqueryアニメーションを次々に持っています:

        books.animate({ left: left1 }, {
            duration: this.slideDuration,
            easing: this.easing,
            complete: complete
        });

        laptops.animate({ left: left2 }, {
            duration: this.slideDuration,
            easing: this.easing,
            complete: complete
        });

アニメーションを同時に実行したいので、次を使用します{queue: false}

books.animate({ left: left1 }, {
            duration: this.slideDuration,
            easing: this.easing,
                            queue: false,
            complete: complete
        });

        laptops.animate({ left: left2 }, {
            duration: this.slideDuration,
            easing: this.easing,
                            queue: false,
            complete: complete
        });

しかし、完了したコールバックが2回呼び出されました。両方のアニメーションがいつ行われるかを正確に知るにはどうすればよいですか?

4

4 に答える 4

1

completeアニメーションの1つからハンドラーを削除してみませんか?

投稿したコードの抜粋から、両方のアニメーションで同じ期間とイージングメソッドを使用しているように見えます。したがって、同時に呼び出されている限り、それらが同時に完了することは本質的に真実です...

于 2012-11-26T23:00:12.230 に答える
1

これは何か複雑に聞こえるかもしれませんが、なぜDeferred Objectsですか?

http://api.jquery.com/category/deferred-object/

ここで、遅延パイプを使用したjQueryアニメーションについて詳しく調べることができます か?

于 2012-11-26T23:02:14.053 に答える
1

jQueryの遅延メソッドを使用して試してください

$.when( 
    books.animate({ left: left1 }, {
        duration: this.slideDuration,
        easing: this.easing
    }),
    laptops.animate({ left: left2 }, {
        duration: this.slideDuration,
        easing: this.easing
  })
).done( function( ) {

    alert("done!");

});

ここでフィドル

于 2012-11-26T23:13:32.630 に答える
0

http://darcyclarke.me/development/using-jquery-deferreds-with-animations/によると:

books.animate({ left: left1 }, {
    duration: this.slideDuration,
    easing: this.easing,
    queue: false
});

laptops.animate({ left: left2 }, {
    duration: this.slideDuration,
    easing: this.easing,
    queue: false
});

$.when(books, laptops).done(complete);
于 2012-11-26T23:20:28.797 に答える