DEV Community


Discussion on: Page scroll progress bars

matthijsewoud profile image

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.

debadeepsen profile image
debadeepsen Author

Thanks for the input. Yes, that is a very good point I had not thought about.

Forem Open with the Forem app