Compose an IntersectionObserver with custom rootMargin and threshold list, scroll a live target through the viewport box, and watch each IntersectionObserverEntry fire in real time. Copy the snippet for lazy-loading, infinite scroll, scrollspy, or sticky-on-pin patterns.
null root uses the viewport. Setting a scrollable element scopes intersection to that element.px or %.0..observe() with the current intersection state.rootMargin with a % unit is resolved relative to the root's box (the viewport, when root is null).0px 0px -50% 0px) is the classic "fire when the element crosses the middle" trick used by scrollspy.threshold: 1 fires only when the target is fully inside the root box — if the target is taller than the root, that never happens.