Function: observeScroll()
ts
function observeScroll(
element,
onScroll,
onScrollStop?): () => void;Observes the scroll event on the specified element and triggers the provided callbacks.
Parameters
| Parameter | Type | Description |
|---|---|---|
element | HTMLElement | The element to observe scroll events on. |
onScroll | (event?) => void | The callback function to execute when a scroll event occurs. |
onScrollStop? | () => void | The 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