Lurker News

Comments (124) 49 threads

Show all comments

Showing thread 4 of 49

valleyer2 replies#
Neat concept.

As someone not very up-to-date in Web UI techniques, I was curious as to how the array was being advanced on scroll. Unfortunately, it looks like the answer is basically polling. The code constantly calls window.requestAnimationFrame(), checking window.pageYOffset. This means that the page is constantly doing work, even at idle.
Surely the more correct way is to install an onscroll handler or something, right?

vincentriemer1 reply#
The correct way would be a mix of those two strategies: an onscroll handler that schedules an update through requestAnimationFrame (ensuring that it only gets scheduled once until the next frame update actually executes).
goatherders2 replies#
The correct way is the way that works, which this does.
osrec1 reply#
Well, perhaps, but it's unnecessarily inefficient.

Continue this thread — 1 reply

framecowbird#
it barely works for me on mobile. very jittery
have_faith#
Request animation frame exists specifically to avoid ‘traditional’ polling. You’re thinking more of setInterval() which is the old way of doing it. The requestAnimationFrame docs are a good read, there are lots of performance benefits.