0
我试图添加到我的网站导航平滑滚动,但我有一个艰难的时间搞清楚为什么滚动从错误的偏移量开始,然后正确移动。滚动从铬错误的偏移量开始,但在Firefox上工作正常
$(window).on("scroll", function() {
var scroll_start = window.scrollY;
console.log(scroll_start);
if (scroll_start > offset) {
navToLight();
} else {
navToDark();
}
});
我这是怎么处理的导航锚单击事件:
$('a.nav-link').on('click', function() {
var target = $($(this).attr('href')).position().top;
console.log("This is the target: "+target);
$("html, body").animate({
scrollTop: target
}, 700);
});
这是我在控制台中看到当我尝试导航到该网站的“关于部分”。