【问题标题】:javascript mobile crossbrowser determine if user scrolled to the bottom of pagejavascript移动跨浏览器确定用户是否滚动到页面底部
【发布时间】:2012-09-11 19:27:07
【问题描述】:

您好,我的问题位于:

javascript crossbrowser determine if user scrolld to the bottom of page

我怎样才能把它写成移动兼容?

window.onscroll = function () {
if (document.body.scrollHeight == (document.body.scrollTop + document.body.clientHeight)) {
            alert("ok");
        }
    }

谢谢

【问题讨论】:

    标签: javascript android iphone mobile


    【解决方案1】:

    我不知道这是否有帮助。

    正如你所说,你可以得到当前的滚动高度,如果你 在页面底部放置一个锚点?并使用脚本作为

    var curr = document.body.scrollHeight;
    document.location.href = "#bottompage";
    if(curr == document.body.scrollHeight) {
      alert("Bottom of page");
    }
    

    【讨论】:

    • 我需要显示一个列表..当您到达列表末尾时,它应该加载接下来的 30 条记录,这就是为什么我需要一个跨浏览器移动设备来查看我何时位于底部页面以调用将加载下一条记录的函数。看你的例子似乎总是 curr=document.body.scrollHeight 所以我总是会收到警报。我不需要将用户发送到页面底部..我需要检测他何时到达那里以便为他服务接下来的 30 条记录...
    • 是的,这可能是个问题,您可以尝试使用前 2 行代码,然后使用 document.body.scrollHeight=curr 重置 pos 但我认为这不是一个好主意如果要动态加载下一条记录,我会说现在是时候执行此操作了,而您还有 10 条记录要显示。
    • 您也可以尝试将事件添加到<body>onmouseover,然后在每个事件中通过使用var e=event.target||event.srcElement; 获取使用的女巫元素这还需要您执行循环 for 循环到您找到具有已知 pos 的目标元素。不知道这是否适用于手机。
    • 与此同时,我们改变主意,因此不再使用此功能..所以我想我会将您的答案标记为已接受,谢谢
    猜你喜欢
    • 2012-02-13
    • 2011-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多