-
Notifications
You must be signed in to change notification settings - Fork 0
/
stopwatch.html
227 lines (197 loc) · 6.09 KB
/
stopwatch.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css" />
<title>Life Tracker - Stopwatch</title>
<style>
#timerTitle {
font-size: 45px;
padding: 50px 0;
}
.timer-image {
width: 20%;
height: auto;
}
#timerSection input {
font-size: 1.5rem;
padding: 10px;
margin: 5px;
width: 80px;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
#timerSection p {
font-size: 2rem;
font-weight: bold;
margin: 10px 0;
}
#timerSection button {
font-size: 1.2rem;
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
#timerSection button:hover {
background-color: #555;
color: white;
transform: scale(1.05);
}
#timerSection button:active {
background-color: #333;
}
#reset {
background-color: rgb(210, 210, 210);
color: white;
}
.highlight {
background-color: yellow;
}
@keyframes blink {
50% {
background-color: red;
color: white;
}
}
.blink {
animation: blink 1s steps(2, start) infinite;
}
.switch-button {
background-color: #333;
color: #fff;
border: none;
padding: 10px 20px;
margin: 5px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s, transform 0.2s;
}
.switch-button:hover {
background-color: #555;
}
.switch-button:active {
transform: scale(0.95);
}
#timerSection input {
border: 2px solid #333;
border-radius: 5px;
padding: 5px;
margin: 5px;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: block;
position: absolute;
min-width: 160px;
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
footer {
margin-top: 50px;
padding: 20px;
background-color: #333;
color: white;
}
</style>
</head>
<body>
<h1>Life Tracker</h1>
<ul>
<li><a href="scheduler.html">Scheduler</a></li>
<li class="dropdown">
<a href="timer.html">Timer</a>
<div class="dropdown-content">
<a href="stopwatch.html" id="selected-list">Stopwatch</a>
</div>
</li>
<li><a href="song.html">Song</a></li>
<li><a href="diary.html">Diary</a></li>
<li><a href="myPage.html">My page</a></li>
</ul>
<br><br><br>
<img id="start" src="start.png" alt="Timer Image" class="timer-image" />
<div id="timerSection">
<h2>Stopwatch</h2>
<p id="timerDisplay">00:00:00</p>
<button id="reset">Reset</button>
</div>
<script>
let isRunning = false;
let timer;
let startTime;
let elapsedTime = 0;
const reset = document.getElementById("reset");
function updateTime() {
const now = Date.now();
elapsedTime = now - startTime;
const seconds = Math.floor((elapsedTime / 1000) % 60);
const minutes = Math.floor((elapsedTime / (1000 * 60)) % 60);
const hours = Math.floor((elapsedTime / (1000 * 60 * 60)) % 24);
document.getElementById('timerDisplay').textContent =
`${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
}
function startTimer() {
startTime = Date.now() - elapsedTime;
timer = setInterval(updateTime, 1000);
localStorage.setItem('startTime', startTime);
document.getElementById("start").src = "stop.png";
isRunning = true;
}
function stopTimer() {
clearInterval(timer);
localStorage.setItem('elapsedTime', elapsedTime);
document.getElementById("start").src = "start.png";
isRunning = false;
}
function resetTimer() {
clearInterval(timer);
elapsedTime = 0;
document.getElementById('timerDisplay').textContent = "00:00:00";
document.getElementById("start").src = "start.png";
localStorage.removeItem('startTime');
localStorage.removeItem('elapsedTime');
isRunning = false;
}
document.getElementById('start').addEventListener('click', () => {
if (isRunning) {
stopTimer();
} else {
startTimer();
}
});
reset.addEventListener("click", resetTimer);
window.onload = () => {
const savedStartTime = localStorage.getItem('startTime');
const savedElapsedTime = localStorage.getItem('elapsedTime');
if (savedStartTime) {
startTime = parseInt(savedStartTime, 10);
elapsedTime = Date.now() - startTime;
startTimer();
} else if (savedElapsedTime) {
elapsedTime = parseInt(savedElapsedTime, 10);
document.getElementById('timerDisplay').textContent =
new Date(elapsedTime).toISOString().substr(11, 8);
}
};
</script>
<br>
<br>
<br>
<br>
<footer>
<p >© 2024 Life Tracker.</p>
</footer>
</body>
</html>