Skip to content

Instantly share code, notes, and snippets.

@wangwen1220
Last active January 2, 2016 10:49
Show Gist options
  • Save wangwen1220/8292981 to your computer and use it in GitHub Desktop.
Save wangwen1220/8292981 to your computer and use it in GitHub Desktop.
JS: jQuery 实现的内部链接平滑滚动 | smoothscroll web links
// 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