/ Published in: JavaScript
A simple countDown class in Javascript:
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * CountDown Class * * @author Giovambattista Fazioli * @email [email protected] * @web http://www.undolog.com * * @param dd (string) 'month day, year' * */ function countDown( dd ) { // init target time var target = new Date( dd ); this.targetTime = target.getTime(); /** * refresh countdown */ this.refresh = function() { var today = new Date(); var currentTime = today.getTime(); // time left this._leftMilliseconds = (this.targetTime - currentTime); this._leftSeconds = Math.floor( this._leftMilliseconds / 1000 ); this._leftMinutes = Math.floor( this._leftSeconds / 60 ); this._leftHours = Math.floor( this._leftMinutes / 60 ); // no module this.leftDays = Math.floor( this._leftHours / 24 ); // for print this.leftMilliseconds = this._leftMilliseconds % 1000; this.leftSeconds = this._leftSeconds % 60; this.leftMinutes = this._leftMinutes % 60; this.leftHours = this._leftHours % 24; } this.refresh(); }
URL: http://www.undolog.com/2008/10/13/una-classe-countdown-in-javascript/