This is a simple vanilla javascript-based countdown timer.
N.B. Not designed for anything other than simple displays, as it makes assumptions (365 days / year, 30 days / month, no leap year handling...)!
Node
npm install countdown.to --save
Bower
bower install countdown.to --save
If using node.js, require the module
var CountdownTo = require('countdown.to');
To create a new countdown timer targeting a specific date:
// Create a new timer
var timer = new CountdownTo('2015-12-25 00:00:00');
To update the display when the time remaining is recalculated:
var timer = new CountdownTo('2015-12-25 00:00:00', { onCalculateRemainingTime: function() {
var c = this;
document.getElementById('myTimerDiv').innerHTML = c.timeRemainingForDisplay();
});
Other API & options described below.
Callback function called when countdown timer initialises.
Callback function called when countdown timer reaches 0.
Callback function called when the remaining time is recalculated.
Interval in milliseconds at which remaining time is recalculated (default: 500)
The display units for each time unit that is calculated (default: ['years', 'months', 'days', 'hours', 'minutes', 'seconds']
)
npm test