Last active
April 20, 2021 16:38
-
-
Save jessedmatlock/ef3d95f86472497a300f7fa04c2a304c to your computer and use it in GitHub Desktop.
Scroll to URL Hash element on page load
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
/* | |
* 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