gpt4 book ai didi

jquery - 为scrolltop添加100px空间

转载 作者:行者123 更新时间:2023-12-01 06:22:53 25 4
gpt4 key购买 nike

我正在使用以下 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com