Team:Heidelberg/Templates/countd-js

From 2013.igem.org

Revision as of 14:26, 3 October 2013 by Nils.kurzawa (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 += '
DAYS
'+day+'
'; timer += '
HOURS
'+hour+'
'; timer += '
MINS
'+this.addZero(min)+'
SECS
'+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 here
var timer = new CountdownTimer('CDT',tl,'
Time is up!
');
timer.countDown();

} window.onload=function(){

CDT();

}