Created
December 7, 2020 08:37
-
-
Save elliottmangham/853c7afb714ed3f8a8a86b4e34772165 to your computer and use it in GitHub Desktop.
JS / Utilities / Scroll to hash
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 to ID (hash links) | |
**************************************************************/ | |
function fnScrollToID( oEvent ) { | |
// Prevent default anchor behaviour | |
oEvent.preventDefault(); | |
// Get offset value (optional) | |
var iOffset = $( this ).attr( 'data-scroll-offset' ); | |
// Animate to new location on-click | |
$( 'html, body' ).animate({ | |
scrollTop: $( $( oEvent.currentTarget ).attr( 'href' ) ).offset().top - ( iOffset ? iOffset : '0' ) | |
}, 1500, 'easeInOutQuart' ); | |
} | |
// END OF DOCUMENT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment