我有以下代码滚动到某个元素:
$('html, body').animate({
scrollTop: $("#maincontent").offset().top
}, 400);
Run Code Online (Sandbox Code Playgroud)
但是,我在顶部有一个固定的导航栏,因此希望能够抵消这一点。如何将其偏移多个像素?
尝试
$('html, body').animate({
scrollTop: $("#maincontent").offset().top - 100 // Means Less header height
},400);
Run Code Online (Sandbox Code Playgroud)