Skip to content

Function: observeScroll()

ts
function observeScroll(
   element, 
   onScroll, 
   onScrollStop?): () => void;

Observes the scroll event on the specified element and triggers the provided callbacks.

Parameters

ParameterTypeDescription
elementHTMLElementThe element to observe scroll events on.
onScroll(event?) => voidThe callback function to execute when a scroll event occurs.
onScrollStop?() => voidThe optional callback function to execute when scrolling stops.

Returns

A function to stop observing scroll events.

() => void

Example

ts
const el = document.createElement('div')
document.body.appendChild(el)
const stop = observeScroll(el, () => console.log('scrolled'))
console.log(typeof stop)

Since

1.0.0

Released under the MIT License.