在jQuery的文檔確定鏈jQuery效果,是說,如果你想添加一個類上的選擇施加影響後,你必須使用一個回調:爲什麼,而不是使用回調
// Fade in all hidden paragraphs; then add a style class to them (not quite right)
$("p.hidden").fadeIn(750).addClass("lookAtMe");
// Fade in all hidden paragraphs; then add a style class to them (correct with animation callback)
$("p.hidden").fadeIn(750, function() {
// this = DOM element which has just finished being animated
$(this).addClass("lookAtMe");
});
但是,你可以鏈兩所方面的影響,而無需使用回調:
$(".something").fadeOut().fadeIn();
這是爲什麼?你不應該有使用回調這個樣子,太:
$(".something").fadeOut(750, function() {
$(this).fadeIn();
});
這裏有一條重要的線索:https://learn.jquery.com/effects/queue-and-dequeue-explained/ –
試着鏈接一個需要時間的效果,看看會發生什麼。基本上可以歸結爲當你想要鏈條中的下一個東西時應用。馬上,或之前的事情完成後。 – David
應該指出,當沒有持續時間傳遞給jQuery動畫方法時,行爲與傳遞給方法的持續時間不同。 – guest271314