Created
May 5, 2024 15:51
-
-
Save mikeoberdick/f651d2492a7c01899a6d1c4129255341 to your computer and use it in GitHub Desktop.
Don't reload page when clicking a jump link from nav menu that references a place on the same page
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
$('.page-template-about .dropdown-menu a').click(function(event) { | |
//don't reload the page and jump to that section | |
event.preventDefault(); | |
//get the section to jump to | |
var hash = this.hash.substr(1); | |
//offset the nav height for fixed nav | |
var navHeight = $('#wrapper-navbar').outerHeight(); | |
var sectionOffset = $('#' + hash).offset().top; | |
//jump to the section programatically | |
$('html, body').animate({ | |
scrollTop: (sectionOffset - navHeight) | |
}, 0 ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment