我正在使用以下 jQuery 函数滚动到单页站点内的 div ID:
$('a').click(function(){
var top = $('html').find($(this).attr('href')).offset().top;
$('html, body').animate({scrollTop: top},1500, 'easeInOutCubic');
return false;
});
有没有办法使用 jQuery 在每个 div 上方添加 100 像素的空间?
我在浏览器窗口顶部有一个固定位置的菜单,并且需要在滚动到菜单时将 div 保留在菜单下方。
最佳答案
不确定我的问题是否正确,但这听起来很容易实现:
...
var top = $('html').find($(this).attr('href')).offset().top - 100;
...
关于jquery - 为scrolltop添加100px空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16701739/