-
Notifications
You must be signed in to change notification settings - Fork 0
/
stopwatch.js
58 lines (48 loc) · 1.57 KB
/
stopwatch.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
$(document).ready(() => {
$("#circle").click(() => {
$("#body").css('background', '#FFF');
$("#circle").css({'visibility': 'hidden', 'display': 'none'});
$("#stopwatch").css({'visibility': 'visible', 'display': 'block'});
$("#stop").css({'visibility': 'visible', 'display': 'block'});
$("#container").css('display', 'block');
var interval = setInterval(() => {
let time = $("#stopwatch").text().split(':');
let min = Number(time[0]);
let sec = Number(time[1]);
let ml = Number(time[2]);
let newTime = time;
ml += 1;
if (ml == 99){
if (sec == 59){
min += 1;
sec = 0;
ml = 0;
}
else {
sec += 1;
ml = 0;
}
}
min = min < 10 ? '0' + min : min;
sec = sec < 10 ? '0' + sec : sec;
ml = ml < 10 ? '0' + ml : ml;
newTime = min + ':' + sec + ':' + ml;
$("#stopwatch").html(newTime);
} ,10);
$(".stop").click ( () => {
clearInterval(interval);
$(".stop").html('Back');
$(".stop").attr('class', 'back');
$(".back").click( () => {
$("#body").css('background', '#27274e');
$("#circle").css({'visibility': 'visible', 'display': 'block'});
$("#stopwatch").css({'visibility': 'hidden', 'display': 'none'});
$("#stop").css({'visibility': 'hidden', 'display': 'none'});
$("#container").css('display', 'flex');
$("#stopwatch").html('00:00:00');
$(".back").html('Stop').
$(".back").attr('class', 'stop');
});
});
});
});