Skip to content

Instantly share code, notes, and snippets.

@elliottmangham
Created December 7, 2020 08:37
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 elliottmangham/853c7afb714ed3f8a8a86b4e34772165 to your computer and use it in GitHub Desktop.
Save elliottmangham/853c7afb714ed3f8a8a86b4e34772165 to your computer and use it in GitHub Desktop.
JS / Utilities / Scroll to hash
/**************************************************************
* 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