2017-08-16 115 views
-2

我希望能夠在一堆事件中使用回調,但不能在末尾使用回調。我試圖做到這一點,但似乎代碼在回調被調用後轉義任何效果。jQuery:如何在`animate()`函數完成後觸發回調函數

$(this).animate({//animate image 
       top:0 
      }, aniTime) 

      .delay(1000, function(){ 

      //some code 

      }) 

      .animate({//animate image 
       top:250 
      }, aniTime) 

有沒有辦法做到這一點或不可能/最佳做法?

+0

我不明白這個quesion – Liam

+0

所以要動畫頂部爲0,等待1000毫秒,然後動畫上到250? –

+0

延遲到下一個動畫爲止,但想要淡入回調中的其他選擇器。有道理?我知道我可以在範圍之外做到這一點,但是想知道是否可以保持代碼整齊。 – RobJShillito

回答

1

您可以通過使用animate的complete回調參數來實現此效果。這將在延遲時間開始的同時運行第一個動畫完成時的內容。

例子:

$(this).animate({//animate image 
     top:0 
    }, aniTime, 
    // complete callback follows: 
    function(){ 
     $('otherElement').fadeOut(200); 
    }) 
    .delay(1000) 
    .animate({//animate image 
     top:250 
    }, aniTime) 
+0

完美.....非常感謝:) 應該已經發現,一個真的....謝謝 – RobJShillito

+0

偉大請標記答案正確 –

+0

完成和完成:) – RobJShillito

相關問題