在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