首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >JQuery检测底部滚动

JQuery检测底部滚动
EN

Stack Overflow用户
提问于 2011-11-22 08:01:29
回答 10查看 27.9K关注 0票数 19

我希望当用户滚动到页面底部时实现内容加载。

我有个问题。它在桌面浏览器上运行得很好,但在移动设备上就不行。我已经实现了一个肮脏的修复来使它在iPhone上工作,但并不是最优的,因为它不能在其他大小的移动设备上工作。

我的网站是www.cristianrgreco.com,向下滚动查看实际效果

问题是在移动设备上添加滚动和高度并不等于高度,而在桌面浏览器上却是这样。

有没有一种方法可以检测移动浏览器?

提前谢谢。

下面是当前正在使用的代码:

$(document).ready(function () {
        $(".main").hide().filter(":lt(3)").show();
        if ($(document).height() == $(window).height()) {
            // Populate screen with content
        }
        else if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {
            window.onscroll = function () {
                if ($(document).height() - $(window).scrollTop() <= 1278) {
                    // At the moment only works on iPhone
                }
            }
        }
        else {
            $(window).scroll(function () {
                if ($(window).scrollTop() + $(window).height() >= $(document).height()) {                     
                    // Works perfect for desktop browsers
                }
            })
        }
})
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8220267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档