I've written a small class to display a timer on the page.  It's not
complete, and could be added to, but here goes.

I release it under the GPLv3 license.

http://cs.earlham.edu/~kevin/Mootools.Timer.js

Of note:

- It's a timer.  You create it with:

var timer = new Timer();
$('clock').timer = new Timer({length: 5000});  // length is in
milliseconds

- It's updates itself on the page:

...
<p id='clock'></p>
...
var timer = new Timer({length: 10000});
timer.setDisplay( $('clock') );
  ... or ...
var timer = new Timer({length: 10000, display: $('clock')});

Putting the two together:
var clock = $('clock');
clock.timer = new Timer({length: 10000, display: clock});

- It's a timer, not clock, so start it:
clock.startTimer(); // will update itself thanks to display:

Other options:
granularity - how often to update a display, defaults to 250ms.
callback - a function to call when timer hits zero.

Currently, it can display up to tenths, but I haven't finished working
that in.  I may not either as the project didn't call for it.  If
someone else wants to take up the flag ...

Reply via email to