当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jquery如何实现锚点链接之间的平滑滚动

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

2019年03月19日  | 移动技术网IT编程  | 我要评论

代码如下:


$('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;
}
}
});

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网