如何使用jquery animate配置滚动速度?

5 jquery jquery-animate

我尝试使用以下代码:

$('#divid').html(html).animate ({scrollTop:0}, "fast"); // Are slow, medium, fast parameters.
Run Code Online (Sandbox Code Playgroud)

我也厌倦了使用这段代码:

$('#divid').html(html).animate ({scrollTop:0}, "500");
Run Code Online (Sandbox Code Playgroud)

我的最终目标是让用户能够配置滚动速度并将该参数传递给animate函数.但是,这两种方法似乎都没有对滚动速度产生影响.我究竟做错了什么?

Sea*_*kin 11

animate函数期望持续时间为字符串或数字.只需将其作为数字传递即可.

$('#divid').html(html).animate ({scrollTop:0}, 500);
Run Code Online (Sandbox Code Playgroud)

  • @CSharper查看文档以了解方法参数的说明.http://api.jquery.com/animate/ (4认同)
  • 500是什么意思?它将在500毫秒内完成整个卷轴? (2认同)