detect-lingering
v1.1.1
Published
Tiny utility for detecting when a user lingers, e.g. if they pause or slow down to look at something while scrolling
Downloads
38
Readme
detect-lingering
Tiny utility for detecting when a user lingers, e.g. if they pause or slow down to look at something while scrolling
installation
npm install detect-lingering
usage
function onLinger () {
console.log('user is lingering!')
}
var detector = createLingerDetector(onLinger, options)
el.onscroll = function () {
// any actual calculations are deferred to a set interval
// detector is very light method, and can be used in the scroll handler
detector.update(el.scrollTop)
}
methods
- update: call this every time your value changes, e.g. scrollTop. Detector uses this to detect lingering
- stop: call this to stop any scheduled calculations
options
- speed: 0.1 // speed below which we consider the user to be lingering
- time: 400 // time the user has to linger for in order for the linger to count
- timeout: 2000 // how long to keep monitoring for changes after the last change
- interval: 50 // how frequently to monitor for changes
demo
npm run demo
run tests
npm test