forked from thorst/jquery-idletimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
63 lines (33 loc) · 1.52 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
jQuery Idle Timer Plugin
Detail: http://paulirish.com/2009/jquery-idletimer-plugin/
Fires a custom event when the user is idle.
Idle is defined by not...
* moving the mouse
* scrolling the mouse wheel
* using the keyboard
Basic idea is presented here:
http://www.nczonline.net/blog/2009/06/02/detecting-if-the-user-is-idle-with-javascript-and-yui-3/
To use:
// idleTimer() takes an optional argument that defines the idle timeout
// timeout is in milliseconds; defaults to 30000
$.idleTimer(10000);
$(document).bind("idle.idleTimer", function(){
// function you want to fire when the user goes idle
});
$(document).bind("active.idleTimer", function(){
// function you want to fire when the user becomes active again
});
// pass the string 'destroy' to stop the timer
$.idleTimer('destroy');
// you can also query if it's idle or not
$.data(document,'idleTimer'); // 'idle' or 'active'
// get time elapsed since user when idle/active
$.idleTimer('getElapsedTime'); // time since state change in ms
// API available in >= v0.9
// bind to specific elements, allows for multiple timer instances
$(elem).idleTimer(timeout|'destroy'|'getElapsedTime');
$.data(elem,'idleTimer'); // 'idle' or 'active'
// if you're using the old $.idleTimer api, you should not do $(document).idleTimer(...)
// element bound timers will only watch for events inside of them.
// you may just want page-level activity, in which case you may set up
// your timers on document, document.documentElement, and document.body