Created
March 25, 2011 09:13
-
-
Save piotrkulpinski/886588 to your computer and use it in GitHub Desktop.
Scroll page to a specific target (#)
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
function scrollTo(target) { | |
// Get the top offset of the target anchor | |
var target_offset = $("#" + target).offset(); | |
var target_top = target_offset.top; | |
// Go to that anchor by setting the body scroll top to anchor top | |
$('html, body').animate({ scrollTop: target_top }, 500); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment