Last active
October 11, 2015 23:50
-
-
Save jeffreysbrother/46a9f0ed7531e1e71403 to your computer and use it in GitHub Desktop.
Smoothly scroll to an element with jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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