jquery如何实现锚点链接之间的平滑滚动

 更新时间:2013年12月02日 17:38:52   作者:  
实现锚点链接之间的平滑滚动的方法有很多,在接下来的文章中为大家介绍下,jquery是如何实现的,感兴趣的朋友不要错过
复制代码 代码如下:

$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body').animate({
scrollTop: targetOffset
},
500);
return false;
}
}
});

相关文章

最新评论