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

Signature TypeScript complète extraite du fichier du composable.

typescript

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

callback
IntersectionObserverCallback
Optional raw IntersectionObserver callback. Called with the full entries array before isIntersecting is updated.
options
MaybeRefOrGetter<IntersectionObserverInit | undefined>
Standard IntersectionObserver init options (root, rootMargin, threshold).

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

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

Exemples

Extraits de code prêts à coller.

Lazy-reveal on scroll

vue

Custom threshold with callback

vue