Skip to content

johnshopkins/scroll-watcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Scroll Watcher

Dispatches a winscroll event when the user scrolls, throttled by a given value (default is 10ms). After a given length of time has passed since the last winscroll event (default is 300ms), a winscroll:done event is dispatched. Within the detail property of the event, you will find the following information:

{
  e: e,                             // original scroll or touchmove event
  depth: <integer>,                 // current scroll depth
  direction: <up|down>,             // which direction is the user srolling
  sinceDirectionChange: <integer>   // how many pixels have been scrolled since the user changed direction
}

Basic usage

const ScrollWatcher = require('scroll-watcher');
const scrollwatcher = new ScrollWatcher();

window.addEventListener('winscroll', (e) => {
  console.log(e.detail);
});

window.addEventListener('winscroll:done', scrollwatcher.handleScroll);

Customization

const ScrollWatcher = require('scroll-watcher');

// time to wait between scroll events
const throttleWait = 50;

// time to wait until scroll is considered complete
const scrollDoneWait = 500;

const scrollwatcher = new ScrollWatcher(throttleWait, scrollDoneWait);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages