gpt4 book ai didi

javascript - 滚动到页面底部附近

转载 作者:行者123 更新时间:2023-11-29 21:28:20 25 4
gpt4 key购买 nike

如何滚动到页面底部附近。我正在使用以下代码滚动到非常底部:

$(document).scrollTop($(document).height());

如何更改此代码以滚动靠近底部?

最佳答案

有多近?

$(document).scrollTop($(document).height() - 1000);

将滚动到底部附近。这里的问题是您还必须考虑视口(viewport)的高度。

get the viewport height 的一种很好的跨浏览器方式是:

var height = Math.max(document.documentElement.clientHeight, window.innerHeight || 0)

然后:

var offset = 100;//your offset. 100px from the bottom here

$(document).scrollTop($(document).height() - (height + offset);

关于javascript - 滚动到页面底部附近,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36947593/

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