useIntersectionObserver
Commons
stable
Creates a reactive IntersectionObserver that tracks whether a bound element is intersecting the viewport. Returns a template ref to attach to the target element and a reactive boolean that flips when the element enters or leaves the visible area.
API
Signature
Full TypeScript signature sourced from the composable file.
API
Parameters
Input parameters accepted by this composable.
- callbackIntersectionObserverCallback
- Optional raw IntersectionObserver callback. Called with the full entries array before isIntersecting is updated.
- optionsMaybeRefOrGetter<IntersectionObserverInit | undefined>
- Standard IntersectionObserver init options (root, rootMargin, threshold).
API
Return values
Properties and methods exposed by the composable return object.
- intersectionRef
- Bind this template ref to the element you want to observe. The observer is automatically attached and re-attached when the ref changes.
- isIntersecting
- Reactive flag that is true when at least one entry in the latest callback batch is intersecting.
Usage
Examples
Ready-to-paste usage snippets.
Lazy-reveal on scroll
Custom threshold with callback