jQueryanimate是一个强大的工具:show, hide, fadeIn, fadeOut, slideUp, slideDown, fadeTo(fadeToggle以及其他我无法忍受的)只是animate带有特定参数的快捷方式(非常类似于 to $.ajax, $.post)$.get。
当动画完成时传递一个回调来触发,就像你用showand做的一样hide:
$("#a").click(function() {
$("#b")
.animate({ borderLeftWidth: "15px" }, 1000, "linear", function() {
//callback -> animation complete
alert("all done");
});
});
您甚至可以将多个调用链接到animate. 可以将回调绑定到对 的每次调用animate,以使其非常复杂(并且容易出错)。
$("#a").click(function() {
$("#b")
.animate({ width: "90%" }, 1000)
.animate({ fontSize: "24px" }, 1000)
.animate({ borderLeftWidth: "15px" }, 1000, "linear", function() {
//callback -> this particular action has been completed
alert("all done");
});
});
作为经验法则,让它简单:)
有关详细信息,请参阅 jQuery 文档:http: //api.jquery.com/animate/