【问题标题】:$(document).height() != $(window).height() in mobile browser$(document).height() != $(window).height() 在移动浏览器中
【发布时间】:2014-09-01 23:11:54
【问题描述】:

之前有人问过这个问题 (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() 报告视口的高度有关,这在移动设备中有所不同。

任何帮助将不胜感激!

【问题讨论】:

标签: javascript jquery-mobile mobile mobile-website infinite-scroll


【解决方案1】:

对我来说神奇的声明,适用于移动设备和桌面 Chrome 浏览器:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-19
    • 1970-01-01
    • 2023-04-05
    • 2014-07-18
    • 2013-01-08
    • 2013-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多