DOM IntersectionObserver Interface
IntersectionObserver tells you when an element enters or leaves the viewport (or another element), for lazy loading, infinite scrolling and scroll animations.
Description
An IntersectionObserver reports when target elements start or stop overlapping the viewport, or a chosen ancestor element. The callback receives entries with isIntersecting, intersectionRatio and the element's position. The threshold option sets how much must be visible, and rootMargin grows or shrinks the area being watched.
It is far more efficient than checking positions in a scroll listener. Typical uses are lazy-loading content, infinite scrolling, pausing off-screen videos and triggering animations as elements appear. Images can often use the simpler loading="lazy" attribute instead.
Each entry also includes boundingClientRect, intersectionRect and rootBounds, which give the exact positions involved, and time, which records when the change happened. The callback runs once when you start observing an element, reporting its initial state, and then each time a threshold is crossed. Call unobserve() once an element no longer needs watching, such as after its content has loaded.
Example
Browser Support
The following information will show you the current browser support for the IntersectionObserver interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





