gpt4 book ai didi

javascript - 移动浏览器中的 $(document).height() != $(window).height()

转载 作者:行者123 更新时间:2023-11-28 07:59:26 27 4
gpt4 key购买 nike

这个问题之前曾被问过(Infinite Scroll on Mobile browsers),但没有得到回应。

我正在尝试实现无限滚动。

检查文档是否在底部,导致更多加载的函数是:

if ($(window).scrollTop() == $(document).height() - $(window).height())

这在我的计算机上运行良好,但不适用于移动设备 (iOS) 上的任何浏览器。

在我的页面的 iPhone 5s 上,$(document).height() 报告为 1055,$(window).height() 为 504。但即使在页面底部,$(window).scrollTop() 也最多为 507。因此 507 != 551 (1055-504)

我相信这可能与 $(window).height() 报告视口(viewport)的高度有关,这在移动设备上有所不同。

如有任何帮助,我们将不胜感激!

最佳答案

对我来说,这句神奇的话适用于移动和桌面 Chrome 浏览器:

$(document).height() - window.visualViewport.height

关于javascript - 移动浏览器中的 $(document).height() != $(window).height(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25613859/

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