是否可以使用jQuery动画scrollTop?
Nick的答案非常有效。在animate()调用中指定complete()函数时要小心,因为你声明了两个选择器(html和body),它会被执行两次。
$("html, body").animate( { scrollTop: "300px" }, { complete : function(){ alert('this alert will popup twice'); } } );
以下是避免双重回调的方法。
var completeCalled = false; $("html, body").animate( { scrollTop: "300px" }, { complete : function(){ if(!completeCalled){ completeCalled = true; alert('this alert will popup once'); } } } );