【发布时间】:2019-07-16 23:20:02
【问题描述】:
我正在使用以下代码为我的网站上的锚点添加平滑滚动。 因为我有一个粘性标题 id 想用 200px 来抵消这个
$('a[href*="#"]:not([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) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
【问题讨论】:
标签: javascript jquery scroll anchor-scroll