【问题标题】:Unable to detect end of web page scrolling in Chrome Android无法在 Chrome Android 中检测到网页滚动结束
【发布时间】:2017-09-03 23:41:26
【问题描述】:

我的页面上有一些 JS/jQuery 代码,一旦用户滚动到页面底部,它们应该执行一个操作。代码如下:

$(window).scroll(function () {
    var position = $(document).scrollTop() + $(window).height();

    if (position >= $(document).height()) {
        // bottom is hit, do something
    }
});

这在我测试过的几种浏览器中运行良好:

  • Mac 版 Chrome
  • Firefox for Mac
  • iOS 版 Safari
  • Firefox for Android

唯一不适用的是 Android 版 Chrome。这个问题至少有一段时间了,但目前在 Chrome Android 版本 57.0.2987.132 上。

有什么想法吗?

【问题讨论】:

  • 我目前遇到了同样的问题,您找到解决方法了吗?
  • 很遗憾,我还没有。我打算很快再来解决这个问题,所以如果我碰巧找到解决方案,我会重新发布。
  • more than a year later 我遇到了同样的问题。如果已解决,请发布答案
  • 好的,我知道了,我的解决方法是,而不是使用$(window).height(),我使用$(myFooterElement).offset().top
  • 仍然不适合我。在切换标签或关闭并重新打开 chrome 后,存在某种错误使其工作。

标签: javascript android jquery google-chrome


【解决方案1】:

您的代码中有错字。

if (position >= $(document).height()) {
    // bottom is hit, do something
});

应该是

if (position >= $(document).height()) {
    // bottom is hit, do something
}

最后没有);

否则,你的逻辑没问题,我在桌面版 Chrome 和 Android 版都测试过。

【讨论】:

  • 谢谢。我的复制/粘贴错误:) 你在 android 上运行的是什么版本的 chrome?
  • 它实际上比你的早 55.0.2883.91 。您可以尝试隔离此功能并在 Android 上独立测试吗?只是为了消除其他代码从其上下文中干扰它的可能性。
  • 如果提供的答案解决了问题,请考虑单击(向上箭头)图标,这意味着该答案很有用。这只是我们不应忽视的社区众多很酷的功能之一。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-05-25
  • 2011-04-27
  • 2011-01-06
  • 1970-01-01
  • 1970-01-01
  • 2016-01-31
  • 2017-06-07
相关资源
最近更新 更多