Jquery mobile jQuery Mobile 1.4无限滚动:窗口滚动未启动

Jquery mobile jQuery Mobile 1.4无限滚动:窗口滚动未启动,jquery-mobile,Jquery Mobile,在jquerymobile1.4中,为什么没有$(窗口)。滚动触发?下面是一个试图检测用户何时滚动到页面末尾的非工作示例: 在不推荐使用pageshow之前,jquerymobile1.3中的这些功能都可以正常工作: 有人知道怎么做吗?你不必使用任何第三方插件来实现无限滚动。你只需要听或者做一些数学题 您需要的是$(window).scrollTop(),$.mobile.getScreenHeight(),$(.ui-content”).outerHeight(),$(.ui-header

在jquerymobile1.4中,为什么没有
$(窗口)。滚动
触发?下面是一个试图检测用户何时滚动到页面末尾的非工作示例:

在不推荐使用
pageshow
之前,jquerymobile1.3中的这些功能都可以正常工作:


有人知道怎么做吗?

你不必使用任何第三方插件来实现无限滚动。你只需要听或者做一些数学题

您需要的是
$(window).scrollTop()
$.mobile.getScreenHeight()
$(.ui-content”).outerHeight()
$(.ui-header”).outerHeight()
$(.ui-footer”).outerHeight()

$(window).scrollTop()
的值与viewport的高度减去content div的高度加上工具栏的高度相匹配时,表示您已到达页面底部

请注意,您应该删除每个固定工具栏检索高度的
1px

滚动停止
侦听器附加到
文档
,然后定义高度变量

$(document).on("scrollstop", function (e) {

        /* active page */
    var activePage = $.mobile.pageContainer.pagecontainer("getActivePage"),

        /* window's scrollTop() */
        scrolled = $(window).scrollTop(),

        /* viewport */
        screenHeight = $.mobile.getScreenHeight(),

        /* content div height within active page */
        contentHeight = $(".ui-content", activePage).outerHeight(),

        /* header's height within active page (remove -1 for unfixed) */
        header = $(".ui-header", activePage).outerHeight() - 1,

        /* footer's height within active page (remove -1 for unfixed) */
        footer = $(".ui-footer", activePage).outerHeight() - 1,

        /* total height to scroll */
        scrollEnd = contentHeight - screenHeight + header + footer;

    /* if total scrolled value is equal or greater
       than total height of content div (total scroll)
       and active page is the target page (pageX not any other page)
       call addMore() function */
    if (activePage[0].id == "pageX" && scrolled >= scrollEnd) {
        addMore();
    }
});
(1)


(1) 在iPhone 5 Safari Mobile上测试

您可以将其绑定到特定页面。但从JQM 1.4.3开始,该事件已被弃用,并替换为无法绑定到特定页面的pagecontainercreate。我尝试了该操作,但它似乎是
$(窗口)。滚动
仍不会启动。我也查看了onPage插件,如中所述,但仍然不走运。我尝试做的只是检测用户何时使用
$(窗口)滚动到底部。滚动
(而不是
$(文档)。滚动
),这样我就可以进行一些无限滚动操作。检查这个非常好的小提琴谢谢!为什么这个方法不更为人所知?为什么jQM文档中没有呢?应该是@MarkBoulder I添加了两个事件的链接。顺便说一句,它是
scrollstop
而不是
scrollend
。请参阅jQM发行版#7563。@MarkBoulder
pagecreate
pagebeforecreate
都不受欢迎,它们都可以直接附加到您想要的任何页面上!很好的一个-这真的很有帮助
$(document).on('pageshow', '.ui-page', function() {
    $(window).scroll(function () {
        if ($(window).scrollTop() + $(window).height() == $(document).height()) {
            alert("Bottom reached!");
        }
    });
});
$(document).on("scrollstop", function (e) {

        /* active page */
    var activePage = $.mobile.pageContainer.pagecontainer("getActivePage"),

        /* window's scrollTop() */
        scrolled = $(window).scrollTop(),

        /* viewport */
        screenHeight = $.mobile.getScreenHeight(),

        /* content div height within active page */
        contentHeight = $(".ui-content", activePage).outerHeight(),

        /* header's height within active page (remove -1 for unfixed) */
        header = $(".ui-header", activePage).outerHeight() - 1,

        /* footer's height within active page (remove -1 for unfixed) */
        footer = $(".ui-footer", activePage).outerHeight() - 1,

        /* total height to scroll */
        scrollEnd = contentHeight - screenHeight + header + footer;

    /* if total scrolled value is equal or greater
       than total height of content div (total scroll)
       and active page is the target page (pageX not any other page)
       call addMore() function */
    if (activePage[0].id == "pageX" && scrolled >= scrollEnd) {
        addMore();
    }
});