我想平稳地向下滚动。我不想为此写函数-特别是如果jQuery已经有一个函数。
3 回答

慕姐4208626
TA贡献1852条经验 获得超7个赞
您可以只使用.animate()该scrollTop属性,如下所示:
$("html, body").animate({ scrollTop: "300px" });

杨__羊羊
TA贡献1943条经验 获得超7个赞
尼克的答案很棒。在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');
}
}
}
);
添加回答
举报
0/150
提交
取消