Looks good, but don't you want to debounce it? Doing onscroll events, even when something has just been draw in the same time-frame, is lots of extra calculations that slow it down.
If you'd use something like requestAnimationFrame, you can cut down on CPU/GPU usage dramatically, or even turn it off completely if the user isn't actively watching it.
You can implement it in a way the onscroll it'll check if isScrolling, and if it isn't, go do the thing with a requestAnimationFrame. The function within that keeps calling itself with another requestAnimationFrame, and keeps unsetting isScrolling.
Full-stack software engineer, experienced in .NET, PHP, Node JS, Angular, Vue, React, and React Native. Master's Degree in Computer Science with focus on HCI. Lover of coffee, videogames, and cats.
Looks good, but don't you want to debounce it? Doing
onscroll
events, even when something has just been draw in the same time-frame, is lots of extra calculations that slow it down.If you'd use something like
requestAnimationFrame
, you can cut down on CPU/GPU usage dramatically, or even turn it off completely if the user isn't actively watching it.You can implement it in a way the
onscroll
it'll check ifisScrolling
, and if it isn't, go do the thing with arequestAnimationFrame
. The function within that keeps calling itself with anotherrequestAnimationFrame
, and keeps unsettingisScrolling
.Thanks for the input. Yes, that is a very good point I had not thought about.