Skip to content

Function: createIntersectionObserver()

ts
function createIntersectionObserver(
   target, 
   callback, 
   options?): IntersectionObserver;

Creates an IntersectionObserver and observes one or more targets.

Parameters

ParameterTypeDescription
targetElement | readonly Element[]The target element or element list.
callbackIntersectionObserverCallbackThe observer callback.
options?IntersectionObserverInitThe observer options.

Returns

IntersectionObserver

The created observer.

Example

ts
const el = document.createElement('div')
document.body.appendChild(el)
const obs = createIntersectionObserver(el, (entries) => console.log(entries))
console.log(obs instanceof IntersectionObserver)

Since

1.0.0

Released under the MIT License.