Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The IntersectionObserver
interface's read-only rootMargin
property is a string with syntax similar to that of the CSS margin
property. Each side of the rectangle represented by rootMargin
is added to the corresponding side in the root
element's bounding box before the intersection test is performed. This lets you, for example, adjust the bounds outward so that the target element is considered 100% visible even if a certain number of pixels worth of width or height is clipped away, or treat the target as partially hidden if an edge is too close to the edge of the root's bounding box.
See The root element and root margin in Intersection Observer API for a more in-depth look at the root margin and how it works with the root's bounding box.