Would strongly second checking out the IntersectionObserver API. Scroll handlers can come with a lot of performance bottlenecks (even if debounced) in execution that blocks the main thread (js is single threaded in nature), slowing everything else on the page .. you might see stuff work smoothly on a developer desktop but when you test on a low end device like an average phone (what your users may be using), you'll see frame drops and jank :( IOs provide async ways to solve problems like this and has been a great addition to the web! If you absolutely need to use scroll listeners, try exploring if "passive" scroll listeners will work for you.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.