1.0.0 • Published 2 years ago

scroll-start-stop-events v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Events for scrollstart & scrollstop

NPM version Bundle size GitHub license

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 in ms after the scrollstop event should fire, when scrolling stops (default: 200)
  • isScrolling … the name of the property that is attached to the element – will be true while scrolling (default: 'isScrolling')

To check if the element is currently scrolling, simply use its property element.isScrolling