-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
133 lines (120 loc) · 3.21 KB
/
index.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stopwatch</title>
</head>
<style>
* {
margin: 0;
padding: 0;
}
body {
width: 100%;
height: 100vh;
background-image: url('https://wallpapercave.com/wp/wp1933766.jpg');
background-position: center;
background-size: cover;
display: flex;
align-items: center;
justify-content: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.container {
padding: 1rem;
max-width: 300px;
text-align: center;
position: relative;
border-radius: 10px;
background-color: rgba(0, 0, 0, 0.6);
}
.time {
padding: 1rem 0;
font-size: 2rem;
}
h1,
p {
color: #f8f8f8;
}
button {
padding: 0.4rem 1rem;
margin: 0 0.2rem;
border-radius: 10px;
border: 1px solid #f8f8f8;
}
button:hover {
background-color: rgba(0, 0, 0, 0.4);
color: #f8f8f8;
}
</style>
<body>
<div class="container">
<h1>Stopwatch</h1>
<p class="time">
<span id="minutes">00</span>:<span id="seconds">00</span>:<span
id="tens"
>00</span
>
</p>
<button id="start">Start</button>
<button id="stop">Stop</button>
<button id="reset">Reset</button>
</div>
</body>
<script>
window.onload = function () {
let minutes = 0;
let seconds = 0;
let tens = 0;
let appendMinutes = document.querySelector('#minutes');
let appendTens = document.querySelector('#tens');
let appendSeconds = document.querySelector('#seconds');
let startBtn = document.querySelector('#start');
let stopBtn = document.querySelector('#stop');
let resetBtn = document.querySelector('#reset');
let Interval;
const startTimer = () => {
tens++;
if (tens <= 9) {
appendTens.innerHTML = '0' + tens;
}
if (tens > 9) {
appendTens.innerHTML = tens;
}
if (tens > 99) {
seconds++;
appendSeconds.innerHTML = '0' + seconds;
tens = 0;
appendTens.innerHTML = '0' + 0;
}
if (seconds > 9) {
appendSeconds.innerHTML = seconds;
}
if (seconds > 59) {
minutes++;
appendMinutes.innerHTML = '0' + minutes;
seconds = 0;
appendSeconds.innerHTML = '0' + 0;
}
};
startBtn.onclick = () => {
clearInterval(Interval);
Interval = setInterval(startTimer, 10);
};
stopBtn.onclick = () => {
clearInterval(Interval);
};
resetBtn.onclick = () => {
clearInterval(Interval);
tens = '00';
seconds = '00';
minutes = '00';
appendTens.innerHTML = tens;
appendSeconds.innerHTML = seconds;
appendMinutes.innerHMTL = minutes;
};
};
</script>
</html>