scroll-start-stop-events
v1.0.0
Published
Apply scrollstart and scrollstop events
Downloads
8
Maintainers
Readme
Events for scrollstart & scrollstop
Simple and lightweight package to apply scrollstart
and scrollstop
events, which are triggered at the beginning and the end of a scroll
event.
Installation
npm i scroll-start-stop-events
or
yarn add scroll-start-stop-events
Usage
Import scroll-start-stop-events
to apply scrollstart
and scrollstop
events to the window
object.
import 'scroll-start-stop-events'
Add event listeners:
window.addEventListener('scrollstart', scrollstartHandler);
window.addEventListener('scrollstop', scrollstopHandler);
Remove event listeners:
window.removeEventListener('scrollstart', scrollstartHandler);
window.removeEventListener('scrollstop', scrollstopHandler);
API
For more control import the default function from scroll-start-stop-events/api
.
import applyScrollStartStopEvents from 'scroll-start-stop-events/api'
applyScrollStartStopEvents(window, 200, 'isScrolling')
Parameters:
element
… the element to apply the scroll events to (default:window
)stopDelay
… the delay inms
after thescrollstop
event should fire, when scrolling stops (default:200
)isScrolling
… the name of the property that is attached to theelement
– will betrue
while scrolling (default:'isScrolling'
)
To check if the element
is currently scrolling, simply use its property element.isScrolling