您的位置:首页 > Web前端 > JQuery

JQuery 实现锚点链接之间的平滑滚动

2016-03-11 16:43 666 查看
24. 解决链接锚点的生硬问题

$('.nav .btn[href*=#],.icon2,.icon3').click(function() {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[id=' + this.hash.slice(1) + ']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body').animate({
scrollTop: targetOffset
},
1000);
return false;
}
}
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: