@rtorcato/browser-common / intersection
intersection
Functions
observeIntersection()
observeIntersection(
element,callback,options?):IntersectionObserver
Defined in: intersection/index.ts:15
Creates an IntersectionObserver and starts observing the given element.
Example
import { observeIntersection, disconnectIntersectionObserver } from '@rtorcato/browser-common/intersection'
const obs = observeIntersection(el, (entries) => entries.forEach((e) => console.log(e.isIntersecting)))
disconnectIntersectionObserver(obs)
Parameters
element
Element
The element to observe.
callback
IntersectionObserverCallback
The callback to run when intersection changes.
options?
IntersectionObserverInit
IntersectionObserver options.
Returns
IntersectionObserver
The created IntersectionObserver instance.
Throws
If IntersectionObserver is unavailable (SSR / Node).
unobserveIntersection()
unobserveIntersection(
observer,element):void
Defined in: intersection/index.ts:38
Stops observing the given element with the provided IntersectionObserver.
Example
import { unobserveIntersection } from '@rtorcato/browser-common/intersection'
unobserveIntersection(obs, el)
Parameters
observer
IntersectionObserver
The IntersectionObserver instance.
element
Element
The element to unobserve.
Returns
void
disconnectIntersectionObserver()
disconnectIntersectionObserver(
observer):void
Defined in: intersection/index.ts:51
Disconnects the IntersectionObserver, stopping all observations.
Example
import { disconnectIntersectionObserver } from '@rtorcato/browser-common/intersection'
disconnectIntersectionObserver(obs)
Parameters
observer
IntersectionObserver
The IntersectionObserver instance.
Returns
void
observeOnce()
observeOnce(
element,callback,options?):IntersectionObserver
Defined in: intersection/index.ts:68
Utility to observe an element once (fires callback only on first intersection).
Example
import { observeOnce } from '@rtorcato/browser-common/intersection'
observeOnce(image, () => loadImage(image))
Parameters
element
Element
The element to observe.
callback
IntersectionObserverCallback
The callback to run on first intersection.
options?
IntersectionObserverInit
IntersectionObserver options.
Returns
IntersectionObserver
The created IntersectionObserver instance.
Throws
If IntersectionObserver is unavailable (SSR / Node).