fn
useIntersectionObserver
v0.0.15testeddemoDetect when an element enters or leaves the viewport via `IntersectionObserver`. Accepts a single target, an array of targets, or a ref/getter resolving to either, plus reactive `rootMargin` and `threshold`.
Example
ts
useIntersectionObserver(el, ([{ isIntersecting }]) => {
visible.value = isIntersecting;
});Demo
Loading demo…
Signature
ts
export function useIntersectionObserver(
target: MaybeComputedElementRef | MaybeComputedElementRef[] | MaybeRefOrGetter<MaybeElement[]>,
callback: IntersectionObserverCallback,
options: UseIntersectionObserverOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
target | any | Element(s) to observe |
callback | IntersectionObserverCallback | Invoked with the observer entries |
options? | UseIntersectionObserverOptions | Options |
Returns
UseIntersectionObserverReturnObserver controls