IntersectionObserver Playground

Rara scrolls her tablet and Bagas logs every entry a real IntersectionObserver hands over: your root, rootMargin and threshold, each target’s ratio, and a…

Why it matters

Lazy-loaded images, infinite scroll, scroll-spy, "appear on scroll" animations: they all use this. The old way, a scroll listener plus getBoundingClientRect() every frame, is wasteful and janky. The observer is worked out by the browser itself and only calls you when something changes.

The key idea

The callback runs when a line is crossed, not on every scroll

Common mistakes

Try it in this playground