Skip to content

Instantly share code, notes, and snippets.

@jeffreysbrother
Last active October 11, 2015 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreysbrother/46a9f0ed7531e1e71403 to your computer and use it in GitHub Desktop.
Save jeffreysbrother/46a9f0ed7531e1e71403 to your computer and use it in GitHub Desktop.
Smoothly scroll to an element with jQuery
$('html, body').animate({
scrollTop: $("#target-element").offset().top
}, 1000);
/*
Experience has shown that this function might not operate as expected if we try to scroll to the top of
some multiple elements with the same class.
For this reason, it seems best to use the id (#) selector and not the class (.) selector.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment