DEV Community

Using requestIdleCallback to create a less janky infinite scroll

Ben Halpern on April 13, 2017

We recently switched from a paginated home feed to one with infinite scroll. We should have done this a while ago, as this makes sitting on the toi...
Collapse
 
raphaeleidus profile image
Raphael Eidus

slight mistake requestIdleCallback(appendPosts(newArticlesHTML), { timeout: 1500 }); needs to be changed to requestIdleCallback(function(){ appendPosts(newArticlesHTML); }, { timeout: 1500 }); otherwise both sides of the if and else execute in the exact same way.

Collapse
 
ben profile image
Ben Halpern

Okay! thanks for the heads up. Interestingly I basically did that in the actual implementation, but I thought I was prettying things up before posting this here. I sometimes forget how JavaScript works in this way until I hit the error and fix. 🙃

I'll update the code in the piece.

Collapse
 
jvanbruegge profile image
Jan van Brügge

How did you calculate distanceFromBottom?

Collapse
 
andybons profile image
Andrew Bonventre

I’m very curious how you implemented a seamless back-button experience to prevent pogo-sticking. Care to share your tricks?