Smoothly Scroll to an Element Without a jQuery Plugin

After spending some time looking for a plugin to do this, I was amazed to see how easy it was to get a smooth scrolling effect using one line of jQuery.  You can use this inside of any callback function.  It works especially well with click.

$('html, body').animate({
	scrollTop: $("#elementID").offset().top
}, 2000);

Although LocalScroll is good for more advanced applications, this snippet is useful for one-time use applications.  Simply adjust #elementID and 2000 to set the element and duration, respectively.

If you enjoyed this article, please share it with a friend!

Comments are closed.