Last active
December 16, 2015 10:58
-
-
Save drainpip/5423729 to your computer and use it in GitHub Desktop.
Assumes jQuery. Simply use class slide for any anchor to move to an ID, eg. <a href="#home" class="slide">Back to top</a>. Adjust duration for length of time. You could also do some math on the duration to make the speed constant based on distance. Remove "return false;" if you want to hashtag to show on the URL.
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() { | |
| $(".slide").click(function() { | |
| $("html, body").animate({ | |
| scrollTop: $($(this).attr("href")).offset().top + "px" | |
| }, { | |
| duration: 500, | |
| easing: "swing" | |
| }); | |
| return false; | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment