-
-
Save codente/599213a206078bfbee0925299a053c90 to your computer and use it in GitHub Desktop.
Make jump links between pages work better when there is a fixed header.
This file contains hidden or 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
| // Adapted from http://stackoverflow.com/questions/30293784/smooth-scroll-to-anchor-after-loading-new-page | |
| NERD.ScrollToHashFix = { | |
| init: function () { | |
| // to top right away | |
| if ( window.location.hash ) scroll(0,0); // void some browsers issue | |
| setTimeout( function() { scroll(0,0); }, 1); | |
| $(function() { | |
| // *only* if we have anchor on the url and if it exists on the page. | |
| if($(window.location.hash).length) { | |
| var hashPos = $(window.location.hash).offset().top; | |
| var headerOffset = 100; | |
| var scrollPos = hashPos - headerOffset; | |
| // smooth scroll to the anchor id | |
| $('html, body').animate({ | |
| scrollTop: scrollPos + 'px' | |
| }, 1000, 'swing'); | |
| } | |
| }); | |
| } | |
| }, | |
| $(window).load(function(){ // wait for the site to finish loading first. | |
| NERD.ScrollToHashFix.init(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment