-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.js
62 lines (49 loc) · 1.17 KB
/
timer.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
50
51
52
53
54
55
56
57
58
59
60
61
62
let time = 0;
let isPaused = true;
const timer = document.getElementById("timer");
let interval;
let tm;
const curTime = () => {
tm = String(time);
const arr = (""+tm).split("");
const addZero = (num) => {
if(num < 10){
return "0" + num;
} else {
return num;
}
}
const min = parseFloat(tm) / 100 / 60;
let floorMin = Math.floor(min);
const decMin = min - floorMin;
const sec = decMin * 60;
let floorSec = Math.floor(sec);
const decSec = sec - floorSec;
let milSec = Math.floor(decSec * 100);
console.log(milSec);
return addZero(floorMin) + ":" + addZero(floorSec) + ":" + addZero(milSec)// milSec[0] + milSec[1];
}
function play()
{
tm = String(time);
isPaused = false;
interval = setInterval(() => {
if(!isPaused) {
const getTime = () => curTime();
time++;
timer.innerHTML = "time: " + getTime();
};
}, 10);
}
function pause()
{
isPaused = true;
clearInterval(interval);
}
function reset()
{
clearInterval(interval);
isPaused = true;
time = 0;
timer.innerHTML = "time: 00:00:00";
}