metafizzy / infinite-scroll

📜 Automatically add next page
https://infinite-scroll.com
7.41k stars 1.74k forks source link

Setting nextPages #883

Closed bmlyon closed 5 years ago

bmlyon commented 5 years ago

I'm using a custom path function per documentation I've found. My problem is that the pages aren't numbered.

var nextPages = [
 'insertPageNameHere',
 'anotherPage',
 'oneMorePage'
];
var infiniteScrollContainer = document.querySelector('.container');
var infScroll = new InfiniteScroll( infiniteScrollContainer, {
  path: function() {
     return nextPages[ this.loadCount ];
  },
  append: '.post',
  checkLastPage: true,
  history: 'push',
  prefill: true
});

When I manually navigate to the second or third page it starts nextPages over again because pageIndex defaults to 1.

How would I set the pageIndex from outside the InfiniteScroll function so that on page3 I can set the count to 3 for example?

PS: I'm using vanilla js rather than jQuery.

desandro commented 5 years ago

See #688 for a similar solution.

bmlyon commented 5 years ago

Thank you. I think I can piece something together with that approach.