2013-08-22 49 views
3

當jQuery動畫完成時,我必須使用回調函數。我一直做的是這樣的:正確的語法jQuery動畫「完成」回調

.animate({ properties }, duration, function() { /* callback */ }); 

然而,這裏提出一個問題時,我已經提出了不同的語法的解決方案。

$('#redirectNoticeContainer').animate({ properties }, { queue: false, duration: 123 }); 

我應該在哪裏放回調函數?這是我的猜測,但它不起作用。

$('#redirectNoticeContainer').animate({ properties }, { queue: false, duration: 123 }, function() { 
console.log("ok"); 
setTimeout(function() { window.location.replace("/Account/Login"); }, 1200); 
}); 

該動畫的作品。回叫不。我應該把它放在哪裏?

+0

http://api.jquery.com/動畫/ –

回答

12

That form of animate()需要complete選項:

$("#redirectNoticeContainer").animate({ 
    // properties... 
}, { 
    queue: false, 
    duration: 123, 
    complete: function() { 
     console.log("ok"); 
     setTimeout(function() { 
      window.location.replace("/Account/Login"); 
     }, 1200); 
    } 
}); 
+0

我完全錯過了那一個。謝謝,它的工作原理! – Saturnix