Overview
IntersectionObserver composable for detecting when an element is visible in the viewport. Perfect for lazy loading, infinite scroll, and visibility detection.Features
- IntersectionObserver API wrapper
- Pause/resume/stop functionality
- Automatic cleanup on unmount
- SSR-safe (checks SUPPORTS_INTERSECTION_OBSERVER)
- Hydration-aware
- Immediate callback option
- Configurable threshold and root margin
Function Signature
Parameters
The element to observe.
The callback to execute when the element’s intersection changes.
Call the callback immediately with synthetic data.
Stop observing after first intersection.
The element used as the viewport. Defaults to browser viewport.
Margin around the root. Can be CSS margin values.
Percentage of target visibility at which to trigger callback.
Return Value
Whether the target element is currently intersecting with the viewport.
Whether the observer is currently active.
Whether the observer is currently paused.
Pause observation.
Resume observation.
Stop observation and clean up.
Examples
Basic visibility detection
Lazy loading images
Infinite scroll
Multiple thresholds
Custom scroll container
Convenience Function: useElementIntersection
Whether the element is currently intersecting.
The intersection ratio (0.0 to 1.0).
Example
Entry Properties
The bounding rectangle of the target element.
The ratio of the intersectionRect to the boundingClientRect.
The rectangle representing the intersection area.
Whether the target is intersecting with the root.
The bounding rectangle of the root element.
The target element being observed.
The time at which the intersection was recorded.
Notes
- Automatically stops observing when
once: trueand element intersects - Hydration-aware: defers setup until client-side hydration completes
- SSR-safe: returns valid API with
isActive: falsewhen IntersectionObserver is not supported immediateoption provides synthetic data on first mount