Have you ever needed to build a UI where some component on the page needs to respond to elements as they’re scrolled to a certain threshold within the viewport — or perhaps in and out of the viewport itself? In JavaScript, attaching an event listener to constantly fire a callback on scroll can be performance-intensive, and if used unwisely, can make for a sluggish user experience. But there is a b
![Building A Dynamic Header With Intersection Observer — Smashing Magazine](https://cdn-ak-scissors.b.st-hatena.com/image/square/ee41c632c128abb8bb6684ed19a44f9e018c69f1/height=288;version=1;width=512/https%3A%2F%2Farchive.smashing.media%2Fassets%2F344dbf88-fdf9-42bb-adb4-46f01eedd629%2F67cc7303-3dc9-4d67-b0f4-b6f77783380f%2Fdynamic-header-intersection-observer.jpg)