A scroll listener that checks visibility runs on every scroll event and measures the element itself, usually with getBoundingClientRect(), which can force a synchronous layout. IntersectionObserver hands that job to the browser. You create it with a callback and options, then observe() each target:
root: the box targets are tested against.null(the default) means the top-level viewport; otherwise an element or document that contains the targets.rootMargin: CSS-margin-style offsets that grow or shrink the root's box.'0px 0px 300px 0px'treats anything within 300 px below the viewport as intersecting.threshold: one ratio or a list, as fractions of the target's area. The default0means any overlap, even edges touching.
In each rendering update, after layout, the browser computes every target's intersection. It queues an entry only when the target moved into a different threshold band or flipped isIntersecting, then calls the callback in a later task with all of that observer's queued entries. An entry has isIntersecting, intersectionRatio, intersectionRect, boundingClientRect, rootBounds, target and time.
Every observe() gives one initial entry, even for an element far off-screen (isIntersecting: false), so the starting state goes through the same code as later changes.
With 20 real wheel steps of 60 px past a target, the page got 20 scroll events and 1 observer callback, in Chrome 156 and Firefox 159, three runs each.
Typical uses: lazy loading, infinite-scroll sentinels, viewability analytics, pausing off-screen video or animation. Native loading="lazy" is itself specified as an IntersectionObserver the browser owns; use the attribute for plain images and iframes, and the API when you need a callback. Call unobserve(target) once a one-shot target is handled and disconnect() to stop everything.