Team:Heidelberg/Templates/countd-js
From 2013.igem.org
function CountdownTimer(elm,tl,mes){
this.initialize.apply(this,arguments);
} CountdownTimer.prototype={
initialize:function(elm,tl,mes) { this.elem = document.getElementById(elm); this.tl = tl; this.mes = mes; },countDown:function(){ var timer=; var today=new Date(); var day=Math.floor((this.tl-today)/(24*60*60*1000)); var hour=Math.floor(((this.tl-today)%(24*60*60*1000))/(60*60*1000)); var min=Math.floor(((this.tl-today)%(24*60*60*1000))/(60*1000))%60; var sec=Math.floor(((this.tl-today)%(24*60*60*1000))/1000)%60%60; var me=this;
if( ( this.tl - today ) > 0 ){timer += ''+day+''; timer += ''+hour+''; timer += ''+this.addZero(min)+''+this.addZero(sec)+'';
this.elem.innerHTML = timer; tid = setTimeout( function(){me.countDown();},10 ); }else{ this.elem.innerHTML = this.mes; return; } },addZero:function(num){ return ('0'+num).slice(-2); }
} function CDT(){
// Set countdown limit var tl = new Date('2013/10/11 16:00:00');
// You can add time's up message herevar timer = new CountdownTimer('CDT',tl,'Time is up!');
timer.countDown();
} window.onload=function(){
CDT();
}