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

Browser supportโ€‹

APIChromeEdgeFirefoxSafariiOS SafariBaseline
IntersectionObserverโœ… 51+โœ… 15+โœ… 55+โœ… 12.1+โœ… 12.2+Widely available

โœ… supported ยท โ— partial ยท โŒ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. 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.