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

实现锚点链接之间的平滑滚动的方法有很多,在接下来的文章中为大家介绍下,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;
}
}
});

以上就是jquery如何实现锚点链接之间的平滑滚动的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » JavaScript 教程