Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 0.79 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Display DIV only if user has been Idle for X amount of time
  2. var timer; // create a timer at first
  3. // restart timer on click
  4. function startIdle() {
  5.     timer = setTimeout(function() { /* show div */ }, time);
  6. }
  7. if (document.addEventListener) {
  8.     document.addEventListener('mouseup', startIdle, false);
  9. }
  10. else {
  11.     document.attachEvent('onmouseup', startIdle);
  12. }
  13. // start the first timer
  14. startIdle();
  15.        
  16. var trigger = 30000
  17. $.(function(){
  18.     setInterval('displayInf()',trigger );
  19.  
  20.     $('body').bind('click dblclick keypress mousemove scroll', function(){
  21.         clearDisplayInf();
  22.     });
  23. });
  24.  
  25. function displayInf()
  26. {
  27.     $('body').append('<div>Your notification div</div>');
  28. }
  29.  
  30. function clearDisplayInf()
  31. {
  32.     trigger = clearInterval(trigger);
  33.     trigger = setInterval('displayInf()', 30000 );
  34. }