npm.io
0.7.1 • Published 3 years ago

scroll-detector

Licence
MIT
Version
0.7.1
Deps
0
Size
29 kB
Vulns
0
Weekly
0
Stars
8

scrollDetector

scrollDetector detects scroll event types: scroll derection and whether page-top or page-bottom or middle.

Latest NPM release MIT License

Example

Usage

$ npm install --save scroll-detector

then

import scrollDetector from 'scroll-detector';

scrollDetector.on( 'scroll', () => {
	console.log( 'scroll' );
} );

scrollDetector.on( 'scroll:up', () => {
	console.log( 'scroll:up' );
} );

scrollDetector.on( 'scroll:down', () => {
	console.log( 'scroll:down' );
} );

scrollDetector.on( 'at:top', () => {
	console.log( 'at:top' );
} );

scrollDetector.on( 'at:bottom', () => {
	console.log( 'at:bottom' );
} );

Other features

  • scrollDetector.isPageTop() whether at the page top or not.
  • scrollDetector.isPageBottom() whether at the page bottom or not.
  • scrollDetector.off( eventName, func ) to remove the listener.
  • scrollDetector.getScrollTop() will return scrollTop amount in pixels.
  • scrollDetector.mute() to disabled the detector.
  • scrollDetector.unmute() to re-enable the detector.

Keywords