Neat Timers
https://github.com/doconix/jquery.powertimer.js
A jQuery plugin that provides the following types of timers:
-
A single-run timer (a.k.a. setTimeout)
-
A repeated-run timer (a.k.a. setInterval)
-
A repeated-run timer that runs immediately, then waits the interval.
-
A repeated-run, definite interval timer (see sleep option below).
-
A repeated-run, definite interval timer that runs immediately, then waits the sleep time.
Why would you use this library vs. the regular setTimeout? Because it provides lots of additional features! For example:
- Automatic timer id tracking.
-
Pausing and later continuing of timers.
-
Unique timers, meaning if you start a timer twice, the first one is automatically cleared.
-
Automatic stopping of timer after a specified number of millis.
-
Automatic timer removal when related elements are removed from the DOM.
-
Multiple, named timers per element.
-
The "this" variable is available in your timed function.
-
Simply return false from a timer function to cancel the timer.
-
A JQuery-like interface for more clear code.
-
Allows parameter passing in both all browsers, including IE which normally doesn't pass parameters nicely
-
Returning of timer options, which provides access to the timer function, etc.