We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Infinite Scrolling?

Development and Programming

Rob Allen's avatar
Rob Allen
3,114 posts
3 months ago
Rob Allen's avatar Rob Allen

Does anyone have any tips on getting infinite scrolling working in EE? Have tried loads of scripts, method but to no avail.

       
User XLYiWdAt's avatar
User XLYiWdAt
9 posts
3 months ago
User XLYiWdAt's avatar User XLYiWdAt

Hrm, I know I’ve seen it done, but can’t remember any specifics.

       
User XLYiWdAt's avatar
User XLYiWdAt
9 posts
3 months ago
User XLYiWdAt's avatar User XLYiWdAt

Is your example ajax powered? If so, should be pretty easy.

       
User rSx7FgmZ's avatar
User rSx7FgmZ
6 posts
3 months ago
User rSx7FgmZ's avatar User rSx7FgmZ

There should be two parts, the EE template serving up content that responds to pagination (the API), and the javascript that loads and inserts that content when the viewport hits a spot in the viewport, while keeping track of pagination. InteractionObserver is the JS part that watches the viewport. Which part are you stuck on?

       
Rob Allen's avatar
Rob Allen
3,114 posts
3 months ago
Rob Allen's avatar Rob Allen

Currently using <https://infinite-scroll.com> which works kind of in that it scrolls but can’t get it to respond to the pagination Pxx values properly. It just scrolls endlessly repeating data after total entries has been reached. The pagination URL (Next page link) get stuck on P15 and doesn’t update when scrolling, when P30 and P45 exist.

I’ve been looking at it too long, it’s probably something simple but I can’t see the wood for the trees!

       
User rSx7FgmZ's avatar
User rSx7FgmZ
6 posts
3 months ago
User rSx7FgmZ's avatar User rSx7FgmZ

Hm, maybe the path? What do you have for that?

Their example has this:

path: 'news/blog-p{{#}}.html'

So does it need to be

path: 'new/P{{#}}'
       
User rSx7FgmZ's avatar
User rSx7FgmZ
6 posts
3 months ago
User rSx7FgmZ's avatar User rSx7FgmZ

I’d also enable debug, it shows you the URL its trying to grab. <https://infinite-scroll.com/options#debug>

       
Rob Allen's avatar
Rob Allen
3,114 posts
3 months ago
Rob Allen's avatar Rob Allen

Cool thanks Blair, will have a look in a while. I did try the P{{#}} version but couldn’t get it to work, so will try again!

       
Hop Studios's avatar
Hop Studios
500 posts
3 months ago
Hop Studios's avatar Hop Studios

Yeah. The basic issue is that EE doesn’t use page numbers; it uses an offset. So you can’t use Infinitescroll’s {#} to auto-determine the next page. You have two choices:

  1. You can use a selector string that grabs the URL of the next page (and that URL is in the results of what you auto-grab each time):
<a href="/page/2class=pagination__next">Next</a>

path: '.pagination__next'
  1. You can set the next page path with a function that returns the next batch based on the current batch, like if you had 10 per page as the limit= …:
path: function() {
  let fetchNumber = ( this.{absolute_count} + 1 ) * {limit};
  return `/articles/P${fetchNumber}`;
}

<https://infinite-scroll.com/options#path>

       
User XLYiWdAt's avatar
User XLYiWdAt
9 posts
3 months ago
User XLYiWdAt's avatar User XLYiWdAt

🎉

       
Rob Allen's avatar
Rob Allen
3,114 posts
3 months ago
Rob Allen's avatar Rob Allen

So I tested the {{#}}version, no joy obviously because of the offset thing Travis!

Tried the path:function method - no luck

The path: 'pagination__next' method works the first time scroll is activated but after that the next page pagination link doesn’t update because the page isn’t refreshed to get the /Pxx slug into the URL.

Scratching my head on this one!

Thanks for your help Travis.

       
User rSx7FgmZ's avatar
User rSx7FgmZ
6 posts
3 months ago
User rSx7FgmZ's avatar User rSx7FgmZ

When you tried the path: function(), what URL did it try?

       
Rob Allen's avatar
Rob Allen
3,114 posts
3 months ago
Rob Allen's avatar Rob Allen

I’m using 15 entries at a time, first scroll console reports P15, next does P16, P17 etc

       
User rSx7FgmZ's avatar
User rSx7FgmZ
6 posts
3 months ago
User rSx7FgmZ's avatar User rSx7FgmZ

If you moved the method back to all javascript, would this work?

let pageNumber = ( this.loadCount + 1 ) * 15;
return `/articles/P${pageNumber}`;
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.