DEV Community 👩‍💻👨‍💻

Discussion on: Hiding and Revealing things with JavaScript pageYOffset

Collapse
 
nicped profile image
Nicolai Høeg Pedersen

Do not use scroll event for this. IntersectionObserver is born for this kind of stuff and performs way better:
developer.mozilla.org/en-US/docs/W...

Collapse
 
sakaz22 profile image
Tatenda Carl Sakarombe Author

Wow, thanks. I never knew about IntersectionObserver. It really performs much better

Collapse
 
nicped profile image
Nicolai Høeg Pedersen

And using pageYOffset is a px based rule - might not be the best option when doing responsive work. The Intersection ratio is an alternative to consider...

Collapse
 
sakaz22 profile image
Tatenda Carl Sakarombe Author

I was wondering of ways I could have changed it in such a way that it would not respond to scrolling after a number to pixels because in my mobile version of the website I made, it would change the content of what I wanted to be changed after a number of pixels. Long story short, this method only worked of laptop but not on mobile so I had to hide whatever I did on laptop for mobile to avoid the bug. Thanks Nicolai for telling me about Intersection ratio and I will look further into it