简体   繁体   English

使用jquery-mobile进行无限滚动

[英]Infinite scrollling with jquery-mobile

I am using infinite scroll on my website, wanted to use the same for my mobile website, however, as soon as I include jquery-mobile, it stops working. 我在网站上使用无限滚动,想在移动网站上使用无限滚动,但是,一旦包含jquery-mobile,它就会停止工作。

It works fine without that. 没有它,它工作正常。 Any pointers? 有指针吗?

Details: I am using Paul Irish's infinite scroll. 详细信息:我正在使用Paul Irish的无限滚动。 Initialization doesn't seem to give any error, but at the same time, it doesn't load the next page(doesn't make the ajax call when I reach the bottom of the page). 初始化似乎没有给出任何错误,但是同时,它不会加载下一页(当我到达页面底部时,不会进行ajax调用)。

I have put up a bare bone site here 在这里架了裸露的骨头

I know it is too late but late is always better than never. 我知道为时已晚,但总比没有好。
You can use the following setInfifniteScroll() function to set up infinite scroll on your page. 您可以使用以下setInfifniteScroll()函数在页面上设置无限滚动。 You can call this function or copy function code directly inside document ready function 您可以在准备好文档的函数内部直接调用此函数或复制函数代码

$(document).ready(function(){
    setInfifniteScroll(scrollingDivId); // Here instead of scrollingDivId you can pass window object
});

Paulirish infinite scroll js has its some predefined algorithm to calculate next page url and if your url doesn't match to it then it will not call the next page. Paulirish无限滚动js具有一些预定义的算法来计算下一页网址,如果您的网址与之不匹配,则它将不会调用下一页。 Therefore i have modified the url to call for next page. 因此,我已经修改了网址以调用下一页。
Here you load you content for first page and then infinite scroll will work from second page. 在这里,您可以为第一页加载内容,然后从第二页开始进行无限滚动。 Note you have maintain one specific path for every page. 请注意,您为每个页面维护一个特定的路径。 example given below has ?page=pageNumber appended to my url. 下面给出的示例在我的网址后附加了?page = pageNumber。

function setInfifniteScroll(scrollingDivId){
    $('#scrollingDivId').infinitescroll({
        state: {
           currPage: 2 ,
           isDestroyed: false,
           isDone: false     
       },  
       loading: {
          finishedMsg: "<em>No more content to load. You have reached to end.</em>",
          img: "image/loader.gif",
          speed: 'fast',
          msgText: "<em>Loading the next set of content...</em>",
          delay  : 1
       },
       navSelector      : "#navId",
       nextSelector     : "#navId a",
       itemSelector     : ".itemselector", // it is element class to catch from your response
       debug            : false,
       dataType     : 'html',
       path: function(pageNumber) {
          var url = $("#navId a").attr("href");
          pageNumber = parseInt(url.substring(url.lastIndexOf("page=")+5, url.length)) + 1;
          $("#navId a").attr("href","nextPageUrl_append with?page=" + pageNumber);
          return url;
       },
    }, function(newElements, data, url){
       // You can perform operations on data
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM