Skip to content

Instantly share code, notes, and snippets.

@jessedmatlock
Last active April 20, 2021 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessedmatlock/ef3d95f86472497a300f7fa04c2a304c to your computer and use it in GitHub Desktop.
Save jessedmatlock/ef3d95f86472497a300f7fa04c2a304c to your computer and use it in GitHub Desktop.
Scroll to URL Hash element on page load
/*
* Scroll the page to the URL Hash, IF URL contains one
* Author: Jesse Matlock - @revivemarketing
*/
if (window.location.hash) {
var element = window.location.hash;
if ($(element).length) {
$('html, body').animate({
scrollTop: $(element).offset().top // IF header is fixed, add height of header in px. eg. '- 140'
}, slow, 'linear');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment