Skip to content

Instantly share code, notes, and snippets.

@BryanBarrera
Created January 25, 2016 20:59
Show Gist options
  • Select an option

  • Save BryanBarrera/4fbd91ba8d6966aa047f to your computer and use it in GitHub Desktop.

Select an option

Save BryanBarrera/4fbd91ba8d6966aa047f to your computer and use it in GitHub Desktop.
animate/scrollTo - if hash is in URL
// if we have anchor on the url
if (window.location.hash) {
// Store the window hash in a variable
var hashname = $(window.location.hash);
// smooth scroll to the id/hash/variable
$('html, body').animate({
scrollTop: hashname.offset().top - 75
}, 500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment