gpt4 book ai didi

javascript - 检查在页面底部附近/底部

转载 作者:行者123 更新时间:2023-11-28 02:17:30 30 4
gpt4 key购买 nike

我需要检查元素是否距离页面底部 x 像素,以动态加载新内容。目前,即使栏位于底部,scrollTop 和高度也不匹配。

jquery 是允许的,虽然基本的 javascript 会更有帮助。

最佳答案

您可能想尝试以下方法(仅在 Firefox 3.5 和 IE 8 中测试):

function pollScrollPosition() {
var y = (document.all) ? document.body.scrollTop : window.pageYOffset;
var max = window.scrollMaxY ||
(document.body.scrollHeight - document.body.clientHeight);

if ((max - y) < 100) {
console.log('Within the bottom 100 pixels. Do Something!');
}
}

// Check the scroll position every 250ms
setInterval(pollScrollPosition, 250);

Firebug 中上述示例的屏幕截图:

Checking is near/at the bottom of the page

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

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