Infinite scroll always pull nextSelector url

一笑奈何 提交于 2019-12-13 10:40:59

问题


I'm looking for a way to have infinite-scroll always use the url retrieved from the "nextSelector" no matter what the url is. The default is that it tries to guess what the url will be, after the first iteration.

I've tried:

  path: function(currentPageNumber) {
    return $(".previous-issue").attr("herf");
  },
  parsePath: function(path, currentPage) {
    return $(".previous-issue").attr("herf");
  },
  pathParse: function(path, currentPage) {
    var month_string = path.replace("/blogs/mindful-matter-2014-", "");
    var month = parseInt(month_string, 10);
    var leading = (month.toString().length == 1) ? "0" + month : month;
    return ["mindful-matter-2014-" + leading];
  },

But they don't have access to the fresh ajax content.


回答1:


  var data_next = $(".previous-issue").attr("href");

  var fetchDataNext = function() {
    console.log(data_next);
    return data_next;
  }

  mindful_matter.infinitescroll = function() {
    if ($('.issue-container').length == 0) return false;
    $('.issue-container').infinitescroll({
      navSelector: ".navigation",
      nextSelector: ".previous-issue",
      itemSelector: ".issue",
      extraScrollPx: 250,
      path: function() {
        return fetchDataNext();
      },
      loading: {
        finished: undefined,
        finishedMsg: "",
        img: "data:image/gif;base64,R0lGODlhAQABAHAAACH5BAUAAAAALAAAAAABAAEAAAICRAEAOw==",
        msg: null,
        msgText: "",
        selector: null,
        speed: 'fast',
        start: undefined
      }
    }, function(newElements, data, url) {

      data_next = $(newElements).attr("data-next");

      console.log(data_next);

      if ($("[data-bg-image]") == 0) return false;
      $("[data-bg-image]").each(function() {
        var $this = $(this);
        var img = $this.attr("data-bg-image");
        $this.backstretch(img);
      });
      mindful_matter.masonry();
    });
  }


来源:https://stackoverflow.com/questions/24442592/infinite-scroll-always-pull-nextselector-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!