Last active
January 2, 2016 10:49
-
-
Save wangwen1220/8292981 to your computer and use it in GitHub Desktop.
JS: jQuery 实现的内部链接平滑滚动 | smoothscroll web links
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
// jQuery 实现的内部链接平滑滚动 | |
$('a[href^="#"]').bind('click.smoothscroll', function(e) { | |
e.preventDefault(); | |
var anchor = this.hash; | |
var $target = $(target); | |
$('html, body').stop().animate({ | |
'scrollTop': $target.offset().top | |
}, 500, 'swing', function() { | |
window.location.hash = anchor; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment