Scroll Direction
This library is my approach to gracefully detecting vertical scroll direction in a browser. It works by keeping track of a series of throttled detect events, then invoking a callback with a direction argument once the series contains only one event direction.
Usage
var s = new ScrollDirection(function (dir) {
console.log(dir)
})
Options
There are two options, series and throttle. Tweak the options to get the desired behavior.
var options = {
series: 5,
throttle: 100
}
new ScrollDirection(callback,options)
Destroy
s.destroy()
Installation
As a library consumed and packaged by something like Webpack or Rollup.
npm install @ryanburnette/scroll-direction
var ScrollDirection = require('@ryanburnette/scroll-direction')
From a CDN.
<script src="https://unpkg.com/@ryanburnette/scroll-direction@1.0.5/dist/scroll-direction.min.js" type="text/javascript"></script>