John_911
John_911

Reputation: 1170

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:

$(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.

Upvotes: 0

Views: 58

Answers (1)

Oscar Paz
Oscar Paz

Reputation: 18312

Use jQuery.animate():

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

jQuery.animate documentation

Upvotes: 1

Related Questions