Deep dive into how IntersectionObserver works
This is a delightfully nerdy exploration of how IntersectionObserver works, its quirks and caveats, and how it can be used to create a JavaScript position: sticky
event as a bonus.
This is a delightfully nerdy exploration of how IntersectionObserver works, its quirks and caveats, and how it can be used to create a JavaScript position: sticky
event as a bonus.
Here’s a secret: You may not need
scroll
events in your next app. Using anIntersectionObserver
, I show how you can fire a custom event whenposition:sticky
elements become fixed or when they stop sticking. All without the use of scroll listeners.[…]
One of the practical limitations of using CSS sticky position is that it doesn’t provide a platform signal to know when the property is active. In other words, there’s no event to know when an element becomes sticky or when it stops being sticky.