Skip to content

Instantly share code, notes, and snippets.

@nataliepo
Created April 27, 2012 18:07
Show Gist options
  • Save nataliepo/2511415 to your computer and use it in GitHub Desktop.
Save nataliepo/2511415 to your computer and use it in GitHub Desktop.
Jquery - scroll to a div.
// if we have an anchor in the url, scroll there.
var parts = window.location.href.split("#");
if (parts.length > 1) {
var target_id = parts[1];
$('html, body').animate({scrollTop:$('#' + target_id).offset().top}, 500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment