-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleStopwatch.html
More file actions
113 lines (100 loc) · 2.9 KB
/
Copy pathSimpleStopwatch.html
File metadata and controls
113 lines (100 loc) · 2.9 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple Stopwatch</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: system-ui, sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #0f172a;
color: white;
}
.box {
background: #1e293b;
padding: 40px 30px;
border-radius: 24px;
text-align: center;
width: 340px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}
h2 {
color: #94a3b8;
font-size: 16px;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 15px;
}
.time {
font-family: monospace;
font-size: 48px;
font-weight: 700;
margin-bottom: 25px;
color: #38bdf8;
}
.btn-group {
display: flex;
gap: 10px;
}
button {
flex: 1;
padding: 12px;
font-weight: 600;
border: none;
border-radius: 10px;
cursor: pointer;
transition: all 0.2s;
}
.start {
background: #0284c7;
color: white;
}
.stop {
background: #ef4444;
color: white;
}
.reset {
background: #475569;
color: white;
}
button:hover {
opacity: 0.9;
}
</style>
</head>
<body>
<div class="box">
<h2>Stopwatch</h2>
<div class="time" id="display">00:00.0</div>
<div class="btn-group">
<button class="start" onclick="start()">Start</button>
<button class="stop" onclick="stop()">Stop</button>
<button class="reset" onclick="reset()">Reset</button>
</div>
</div>
<script>
let timer = null, ms = 0, sec = 0, min = 0;
function start() {
if (timer) return;
timer = setInterval(() => {
ms++;
if (ms >= 10) { ms = 0; sec++; }
if (sec >= 60) { sec = 0; min++; }
document.getElementById("display").innerText =
`${String(min).padStart(2, '0')}:${String(sec).padStart(2, '0')}.${ms}`;
}, 100);
}
function stop() { clearInterval(timer); timer = null; }
function reset() { stop(); ms = sec = min = 0; document.getElementById("display").innerText = "00:00.0"; }
</script>
</body>
</html>