svelte-intersection-observer
- Purpose: A Svelte library that detects if an element is in the viewport using the Intersection Observer API .
- Key Features:
- Tracks element visibility in the viewport reactively.
- Supports one-time observation (
once
prop). - Provides events (
observe
andintersect
) for intersection state changes. - Offers granular control via props like
root
,rootMargin
, andthreshold
.
- Target Audience: Svelte developers needing lightweight, reactive viewport intersection detection.
- Framework Support: Exclusively for Svelte.
- API Highlights:
- Props:
element
,intersecting
,once
,root
,rootMargin
,threshold
,entry
,observer
. - Events:
on:observe
(fires on intersection changes) andon:intersect
(fires only when intersecting). - Data: Events dispatch
IntersectionObserverEntry
details (e.g.,isIntersecting
,boundingClientRect
).
- Props:
- Example Use Cases:
- Lazy-loading content.
- Triggering animations when elements become visible.
- Tracking analytics for viewed sections.
intersection-observerviewportlazy-loadingconditionalsveltesvelte-componenttypescript-definitionsintersection-event
Featured Stories
No featured articles here. Navigate to an article, then pick the Feature on menu button