gpt4 book ai didi

javascript - 无法检测用户何时到达手机上浏览器的末尾

转载 作者:行者123 更新时间:2023-12-01 01:58:46 24 4
gpt4 key购买 nike

我试图检查用户何时到达浏览器底部并使用以下内容:

 var scrollHeight = $(document).height();
var scrollPosition = $(window).height() + $(window).scrollTop();
if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
alert();
}

当我在桌面和 Chrome 模拟器上测试它时,它工作正常,但在真实手机(Android 和 IOS)上它不起作用。

有没有更好的方法来检测手机上滚动的结束?

最佳答案

你可以试试这个:

window.onscroll = function(ev) {
if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight) {
alert("you're at the bottom of the page");
}
};

关于javascript - 无法检测用户何时到达手机上浏览器的末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50787400/

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