Skip to content

@epikodelabs/streamix


@epikodelabs/streamix / dom/src/public-api / onIntersection

Function: onIntersection()

onIntersection(element, options?): Stream<boolean>

Defined in: projects/libraries/streamix/dom/src/lib/streams/onIntersection.ts:27

Creates a reactive stream that emits true when a given element enters the viewport and false when it leaves.

This stream is a wrapper around the IntersectionObserver API and is useful for lazy loading, visibility tracking, and viewport-aware effects.

Behavior:

  • Resolves the element and options once on first subscription.
  • Emits the current intersection state whenever it changes.
  • Starts observing on first subscriber.
  • Stops observing when the last subscriber unsubscribes.
  • Safe to import and subscribe in SSR (no-op).
  • Fully compatible with async iteration.

Parameters

element

MaybePromise<Element>

The DOM element (or promise) to observe.

options?

MaybePromise<IntersectionObserverInit>

Optional IntersectionObserver options (or promise).

Returns

Stream<boolean>

A stream emitting intersection state.

Released under the GNU AGPL v3 or later.