如何使用 jquery animate 配置滚动速度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14260539/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure scroll speed using jquery animate?
提问by Seain Malkin
I tried using the following code:
我尝试使用以下代码:
$('#divid').html(html).animate ({scrollTop:0}, "fast"); // Are slow, medium, fast parameters.
I also tired using this code:
我也厌倦了使用这段代码:
$('#divid').html(html).animate ({scrollTop:0}, "500");
My end goal is have users be able to configure scroll speed and pass in that parameter to the animate function. But, both methods do not seem to make a difference in scroll speeds. What am I doing wrong?
我的最终目标是让用户能够配置滚动速度并将该参数传递给 animate 函数。但是,这两种方法似乎对滚动速度没有影响。我究竟做错了什么?
回答by Seain Malkin
The animate
function expects duration to be either a string or a number. Just pass it in as a number.
该animate
函数期望持续时间为字符串或数字。只需将其作为数字传入即可。
$('#divid').html(html).animate ({scrollTop:0}, 500);