Created
August 10, 2015 13:35
-
-
Save djom202/772049c83084d56a165e to your computer and use it in GitHub Desktop.
Nav to Hash on click
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
| $("#nav ul li a[href^='#']").on('click', function(e) { | |
| // prevent default anchor click behavior | |
| e.preventDefault(); | |
| // store hash | |
| var hash = this.hash; | |
| // animate | |
| $('html, body').animate({ | |
| scrollTop: $(hash).offset().top | |
| }, 300, function(){ | |
| // when done, add hash to url | |
| // (default click behaviour) | |
| window.location.hash = hash; | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment