@rtorcato/browser-common / intersection
intersection
Functions
observeIntersection()
observeIntersection(
element,callback,options?):IntersectionObserver
Defined in: intersection/index.ts:14
Creates an IntersectionObserver and starts observing the given element.
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.
Example
import { observeIntersection, disconnectIntersectionObserver } from '@rtorcato/browser-common/intersection'
const obs = observeIntersection(el, (entries) => entries.forEach((e) => console.log(e.isIntersecting)))
disconnectIntersectionObserver(obs)
unobserveIntersection()
unobserveIntersection(
observer,element):void
Defined in: intersection/index.ts:34
Stops observing the given element with the provided IntersectionObserver.
Parameters
observer
IntersectionObserver
The IntersectionObserver instance.
element
Element
The element to unobserve.
Returns
void
Example
import { unobserveIntersection } from '@rtorcato/browser-common/intersection'
unobserveIntersection(obs, el)
disconnectIntersectionObserver()
disconnectIntersectionObserver(
observer):void
Defined in: intersection/index.ts:47
Disconnects the IntersectionObserver, stopping all observations.
Parameters
observer
IntersectionObserver
The IntersectionObserver instance.
Returns
void
Example
import { disconnectIntersectionObserver } from '@rtorcato/browser-common/intersection'
disconnectIntersectionObserver(obs)
observeOnce()
observeOnce(
element,callback,options?):IntersectionObserver
Defined in: intersection/index.ts:63
Utility to observe an element once (fires callback only on first intersection).
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.
Example
import { observeOnce } from '@rtorcato/browser-common/intersection'
observeOnce(image, () => loadImage(image))