Created
June 19, 2013 15:47
-
-
Save raddevon/5815372 to your computer and use it in GitHub Desktop.
Smooth scrolling anchor links with jQuery.
This script was taken from http://www.paulund.co.uk/smooth-scroll-to-internal-links-with-jquery . I modified it to fix a bug when using it with anchor links pointing to the top of the 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
$('a[href^="#"]').on('click',function (e) { | |
e.preventDefault(); | |
var target = this.hash, | |
$target = $(target); | |
$('html, body').stop().animate({ | |
'scrollTop': ($target.offset()) ? $target.offset().top : 0 | |
}, 400, 'ease', function () { // Set the duration and easing function as desired. | |
window.location.hash = target; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment