Git Product home page Git Product logo

idletimer's Introduction

IdleTimer

Determines when the user is idle (not interacting with the page) so that you can respond appropriately.

Screenshot

How to use

An easy setup of IdleTimer might be something like this:

#JS
var myIdleTimer = new IdleTimer(window, { timeout: 60000 });
myIdleTimer.addEvent('idle', function() {
	alert('You have been idle for 60 seconds!');
});

This would launch an alert box after the user has not moved his mouse button over the document, clicked any mouse/keyboard buttons or scrolled using the mouse scroll wheel.

If you want to use the default settings (60 second timeout), you can also do it even easier by doing something like this:

#JS
window.addEvents({
	'idle': function() { alert('60 seconds have passed!'); },
	'active': function() { alert('You just became active again!'); }
});

If you want to apply the IdleTimer to a specific element on the page, you can get an IdleTimer instance and set it's options like this:

#JS
$('myDiv').get('idle'); // Returns an IdleTimer instance
$('myDiv').set('idle', { timeout: 5000, events: ['mouseover', 'mousedown'] }); // Creates an IdleTimer instance with the given options (does not start it)

Syntax

#JS
new IdleTimer(element, [options]);

Arguments

1. element - (mixed) An Element or an id string.
2. options - (object, optional) the options described below:

Options

  • timeout : (number) Number of idle milliseconds before firing the idle event. Defaults to 60000 (one minute).
  • events : (array) Event names that trigger the active event (resets the idle time). Defaults to ['mousemove', 'keydown', 'mousewheel', 'mousedown']

Events

  • idle : Fired when the user has reached the set amount of idle milliseconds.
  • active : Fired when the user becomes active.
  • start : Fired when the events have been added and the timer is starting for the first time.
  • stop : Fired when the timer has been stopped and the events have been removed.
  • timeoutChanged : Fired when the threshold for idle milliseconds has been set to a new value. Gets passed the new value.

idletimer's People

Contributors

rexxars avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rolfnl learn-alex

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.