A simple counter that counts how much time remains/passed from a spcified date and time. The class was inspired by a joomla pugin called util_counter, which can be found here
#HTML
<div id='res'></div>
Then the JS:
#JS
var counter = new SimpleCounter('res',new Date(2011,12,1));
- element (
String
element id orElement
) : An element to inject the counter into. - time (
Integer
target timestamp orDate
target date): A traget date to cout to/from. NOTE: timestamp provided must be in seconds, and not miliseconds. - options - (
Object
: optional) See below: Options
- format (
string
) : In what way to format the counter (see more below). default is[D] [H] [M] [S]
. - lang (
object
): Alternative words to use or counter. for more detail see source code. - leadingZero (
bool
): whether to add a leading zero to numbers smaller than 10. default istrue
. - continue (
bool
) : whether to start countng upwards when countdown is done. default isfalse
.
The class identifies 4 letters: D
(days), H
(hours), M
(minutes), S
(seconds) surounded by curly bracets. If the letters are capital, the unit's name will be used allongside the unit's number.
Else, if a smal letter is used, only the unit's number will be used.
Examples:
#JS
'{D} {h}:{m}:{s}' // 14 Days 10:34:15
'{D}, {H} and {M}' // 14 Days, 10 Hours and 34 Minutes
done
: Fires when countdown is done