Do something when a timespan of no interaction passes
Do something when a timespan of no interaction passes.
Straightforward;
It sets a timeout that can be reset by internal eventListeners -
or through the public API.
When time passes your callback is executed.
Install the package as npm package. Provided are
a umd-formatted file in the dist folder to require or just read
and an es-module in the module folder to import.
Start watching activity, waiting for inactivity.
optional replace standard events to watch:
let interval = 120000 // 20 minutes
let callback = function () {
if (window.alert('Ready to resume?')) {
inactivityListener.restart()
}
}
let events = ['touchstart', 'pointerdown']
inactivityListener.start(interval, callback[, events])
Reset timer when ticking:
inactivityListener.reset()
Report inactivity, in milliseconds:
let inactiveTime = inactivityListener.lapse
Resume listening after timeout:
inactivityListener.restart()
Remove listeners, clear timer:
inactivityListener.stop()
…/inactivity-listener/demo/inactivityListener.html