Created
August 9, 2012 09:32
-
-
Save rbrunt/3302677 to your computer and use it in GitHub Desktop.
Using #section links with scrollto jquery plugin without any messy jumpiness :)
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
| $(document).ready(function(){ | |
| $('nav a').click(function(e){ | |
| // If a link has been clicked, scroll the page to the link's hash target: | |
| // Links just need their href to be the hash of the section you're scrolling to e.g. #top, no class to choose them... | |
| // This has the advantage that there is no loss in functionality from users without javascript | |
| $.scrollTo( this.hash || 0, 300); | |
| // Update the URL in the browser to the new anchor point | |
| history.pushState(null, null, this.href); | |
| // Prevents the browser actually following the link - no jumping down before scrolling :) | |
| e.preventDefault(); | |
| }); | |
| }); |
Author
You used it anywhere to check out? Currently using scrollTo but not in accessible way for non js support.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e.preventDefault()prevents the browser from updating the url bar