intersection
Thin wrappers around IntersectionObserver for observing element
visibility, including a one-shot observeOnce helper.
Import: @rtorcato/browser-common/intersection
๐ MDN: Intersection Observer API ยท ๐ caniuse: intersectionobserver
Exampleโ
import { observeOnce, disconnectIntersectionObserver } from '@rtorcato/browser-common/intersection'
observeOnce(image, () => loadImage(image))
Exportsโ
observeIntersection(element, callback, options?)โ creates anIntersectionObserverand observeselementunobserveIntersection(observer, element)โ stops observingelementdisconnectIntersectionObserver(observer)โ disconnects the observer entirelyobserveOnce(element, callback, options?)โ firescallbackonce on first intersection, then disconnects
See the API reference for full signatures.