代码之家  ›  专栏  ›  技术社区  ›  Hamed Minaee

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

  •  0
  • Hamed Minaee  · 技术社区  · 6 年前

    我正在尝试检查用户何时到达浏览器底部,并使用以下命令:

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

    当我在桌面和Chrome模拟器上测试它时,它工作得很好,但在真正的手机(包括Android和iOS)上却不工作。

    有没有更好的方法来检测手机上滚动条的末端?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Cuong Vu    6 年前

    试试这个,告诉我它是否有效:

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