Skip to content

Instantly share code, notes, and snippets.

@piotrkulpinski
Created March 25, 2011 09:13
Show Gist options
  • Save piotrkulpinski/886588 to your computer and use it in GitHub Desktop.
Save piotrkulpinski/886588 to your computer and use it in GitHub Desktop.
Scroll page to a specific target (#)
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