A zero dependency, ~5KB library to make idle state detection in the browser an ease. With it's simple but yet powerful API it features everything you will ever need.
npm install idle-timeout
yarn add idle-timeout
<script src="https://unpkg.com/idle-timeout/dist/idle-timeout.min.js"></script>
idleTimeout is totally easy to use. All you basically need to do is:
idleTimeout(() => {
// Do some cool stuff
});
The idleTimeout constructor takes two arguments:
callback [Function]
- The callback functionoptions [Object]
- An optional options objectelement [Element]
- The element to listen for the timeouttimeout [Number]
- The idle timeout (in milliseconds)loop [Boolean]
- Wether the timeout should be looped when idle
const instance = idleTimeout(
() => {
// Callback
},
{
element: document,
timeout: 1000 * 60 * 5,
loop: false
}
);
pause()
- Pauses the timeout
instance.pause();
resume()
- Resumes an paused timeout
instance.resume();
reset()
- Reset the timeout
instance.reset();
destroy()
- Destroy the instance
instance.destroy();
idle [Boolean]
- Wether the current state is idle
instance.idle; // false
timeout = value [Number]
- Set the timeout (in milliseconds)
instance.timeout = 1000 * 60;
loop = value [Boolean]
- Set wether the timeout should be looped
instance.loop = true;
idle = value [Boolean]
- Set the idle state
instance.idle = true;
Chrome |
Firefox |
Safari |
Opera |
Edge |
IE |
---|---|---|---|---|---|
Latest 2 | Latest 2 | Latest 2 | Latest 2 | Latest 2 | 11 |
This project is licensed under the terms of the MIT License.