2

.animate()遅延とイージングを含むすべての要素の機能が完了した後にのみ、機能をトリガーしようとしています。

いくつかの異なる方法を試しましたが、運がありませんでした。アイデアはありますか?

  $("#inner_work").on("mouseenter", ".activeBox", function(){
        var thisBox = $(this).attr('id');
        $("#inner_work [class^='workBox_']").each(function(){
            if($(this).attr('id') != thisBox){
                $(this).stop().delay(randomEasing(200,800)).animate({
                    opacity:0
                }, randomEasing(200,700));
            } else {
                $(this).stop().animate({
                    opacity:1
                }, 'fast');
            }
        }); 
  });

すべてのアニメーションが完了した後にイベントをトリガーするにはどうすればよいですか?

randomEasingランダムにずらして作るのはこの機能だけです

function randomEasing(from,to)
{
    return Math.floor(Math.random()*(to-from+1)+from);
}
4

1 に答える 1

7

.promise()コレクション内のすべての要素のすべてのアニメーションが完了した場合にのみ呼び出されるコールバックを登録するために、遅延オブジェクトを使用してリクエストすることができます。

$("#inner_work [class^='workBox_']").promise().done(function() { 
     ...
});

これは、既存のコードと連鎖できます。

$("#inner_work [class^='workBox_']").each(function() {
    // your existing animation code
}).promise().done(function() {
    ...
});
于 2013-01-02T17:01:13.830 に答える