- Docs
Is Visible
What @samline/is-visible does, how its transitions and shared observers behave, and where to start.
@samline/is-visible reports when elements enter and leave the viewport, or any scroll container. It wraps IntersectionObserver with the details people usually get wrong:
- Any target: an element, a selector, a
NodeListor an array, with one cleanup for all of them. - Honest transitions:
visiblefires once per entry;notVisibleonly after the element was visible. - Shared observers: calls with the same
root,rootMarginandthresholdshare one observer. - Never stuck hidden: without
IntersectionObserver, every element is reported visible once. - Safe on the server: without a DOM, every call returns a no-op cleanup.
Choose your next step
Installation
Package managers, the CDN and the first lazy image.
ExamplesLive previews with the complete, copyable source of each one.
API referenceSignatures and behavior of isVisible, observeVisibility and their callbacks.
Defaults and accepted values of inOut, once, root, rootMargin, threshold and fallback.
React, Vue and Svelte adapters.