简体   繁体   English

如何使用scrolltop动画/平滑滚动到div

[英]How to animated/smooth scroll to div using scrolltop

Can someone help me turn my code into one that will animate the scroll. 有人可以帮助我将我的代码转换为可以使滚动动画的代码吗? I've been researching and trying to do it myself but I'm obviously not doing something correctly. 我一直在研究并尝试自己做,但是显然我做的不正确。

Here is my JS: 这是我的JS:

$(function() { //When the document loads
  $(".jrm-menu-whyus > a").bind("click", function() {
    $(window).scrollTop($("#menu-jrm").offset().top);
    return false;
  });
});

Thanks! 谢谢!

It works fine, just want to animate the scroll. 它工作正常,只想对滚动进行动画处理。

Use jQuery.animate(): 使用jQuery.animate():

$("html, body").animate({scrollTop: $("#menu-jrm").offset().top});

jQuery.animate documentation jQuery.animate文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM