This time I will share jQuery Plugin and tutorial about Detect If The User Is Idle In jQuery – Inactivity, hope it will help you in programming stack.
A tiny and mobile-friendly jQuery idle detection plugin that detects user’s activities (keyboard, mouse, touch, or custom events) and fires an ‘Inactivity’ event when the user has been idle for a certain amount of time.
Default Events To Track:
- mouseEvents: mousemove, mousedown, mousewheel, wheel, DOMMouseScroll, MSPointerDown, MSPointerMove
- keyboardEvents: keypress, keydown, keyup
- touchEvents: touchstart, touchmove, touchend
How to use it:
1. Place the minified version of the Inactivity plugin after loading the latest jQuery.
1 |
< script src = "/path/to/cdn/jquery.slim.min.js" ></ script > |
2 |
< script src = "/path/to/src/jquery.inactivity.min.js" ></ script > |
2. Initialize the plugin on the whole document.
1 |
$(document).inactivity( { |
3. Fire an event when a user is idle.
1 |
$(document).on( "inactivity" , function (){ |
4. Fire an event when a user is active.
1 |
$(document).on( "activity" , function (){ |
5. Determine whether to detect mouse events. Default: true.
1 |
$(document).inactivity( { |
6. Determine whether to detect keyboard events. Default: false.
1 |
$(document).inactivity( { |
7. Determine whether to detect keyboard events. Default: false.
1 |
$(document).inactivity( { |
8. Determine whether to use custom events. Default: ”.
1 |
$(document).inactivity( { |
2 |
customEvents: "customEventName" |
9. Determine whether to trigger only the first “activity” event. Default: false.
1 |
$(document).inactivity( { |
This awesome jQuery plugin is developed by readyforaliens. For more Advanced Usages, please check the demo page or visit the official website.