forked from frontinvale/timer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountdown.js
50 lines (39 loc) · 847 Bytes
/
countdown.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"use strict";
var countdown = function() {
var n,
t,
c,
e = function() {
t = document.querySelector("#timer"), c = document.querySelector(".countdown")
},
i = function(c) {
s();
var e = 60 * c;
t.classList.add("started"), n = setInterval(function() {
e--, a(e), e > 75 || r(), e > 25 || u(), 0 != e || o()
}, 1e3)
},
a = function(n) {
var t = n / 60 >> 0,
e = n - 60 * t + "";
c.textContent = t + ":" + (e.length > 1 ? "" : "0") + e
},
o = function() {
clearInterval(n), t.classList.add("finished")
},
s = function() {
o(), t.classList.value = []
},
r = function() {
t.classList.add("warning")
},
u = function() {
t.classList.add("shake")
};
return {
init: e,
start: i,
clear: s
}
}();
window.onload = countdown.init;