-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
33 lines (30 loc) · 909 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//setup countdown
var timeLeft = 15;
var currentTime = Date.parse(new Date());
var deadline = new Date(currentTime + timeLeft*60*1000);
function countDownTime(deadline){
var t = Date.parse(deadline) - Date.parse(new Date());
var seconds = Math.floor( (t/1000) % 60 );
var minutes = Math.floor( (t/1000/60) % 60 );
var hours = Math.floor( (t/(1000*60*60)) % 24 );
var days = Math.floor( t/(1000*60*60*24) );
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
function startCountdown(id, deadline){
var countdown = document.getElementById(id);
var timeinterval = setInterval(function(){
var t = countDownTime(deadline);
countdown.innerHTML = t.minutes + ':' +
+ t.seconds;
if(t.total<=0){
clearInterval(timeinterval);
}
},1000);
}
startCountdown('countdown', deadline);