Skip to main content

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 an IntersectionObserver and observes element
  • unobserveIntersection(observer, element) โ€” stops observing element
  • disconnectIntersectionObserver(observer) โ€” disconnects the observer entirely
  • observeOnce(element, callback, options?) โ€” fires callback once on first intersection, then disconnects

See the API reference for full signatures.