-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.html
225 lines (196 loc) · 7.02 KB
/
timer.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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Life Tracker - Timer</title>
<link rel="stylesheet" href="style.css" />
<style>
#timerTitle {
font-size: 45px;
padding: 50px 0;
}
.timer-image {
width: 20%;
height: auto;
cursor: pointer;
}
#timerSection input {
font-size: 1.5rem;
padding: 10px;
margin: 5px;
width: 60px;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
#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;
}
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" id="selected-list">Timer</a>
<div class="dropdown-content">
<a href="stopwatch.html">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>Timer</h2>
<input type="number" id="hours" placeholder="HH" min="00" max="99" />
<input type="number" id="minutes" placeholder="MM" min="00" max="59" />
<input type="number" id="seconds" placeholder="SS" min="00" max="59" />
<br>
<button id="reset">Reset</button>
</div>
<script>
document.addEventListener("DOMContentLoaded", function () {
let timerInterval;
let timerRunning = false;
const startImage = document.getElementById("start");
const resetButton = document.getElementById("reset");
function playAlarm() {
const audio = new Audio("alarm.mp3");
audio.play();
clearInterval(timerInterval);
startImage.src = "start.png";
timerRunning = false;
}
function startTimer() {
const hours = parseInt(document.getElementById("hours").value) || 0;
const minutes = parseInt(document.getElementById("minutes").value) || 0;
const seconds = parseInt(document.getElementById("seconds").value) || 0;
let totalTime = hours * 3600 + minutes * 60 + seconds;
if (totalTime > 0 && !timerRunning) {
timerInterval = setInterval(function () {
if (totalTime <= 0) {
clearInterval(timerInterval);
timerRunning = false;
playAlarm();
alert("Time's up!");
} else {
totalTime--;
document.getElementById("hours").value = Math.floor(totalTime / 3600).toString().padStart(2, "0");
document.getElementById("minutes").value = Math.floor((totalTime % 3600) / 60).toString().padStart(2, "0");
document.getElementById("seconds").value = (totalTime % 60).toString().padStart(2, "0");
}
}, 1000);
startImage.src = "stop.png";
timerRunning = true;
}
}
function stopTimer() {
clearInterval(timerInterval);
startImage.src = "start.png";
timerRunning = false;
}
function resetTimer() {
clearInterval(timerInterval);
timerRunning = false;
document.getElementById("hours").value = "00";
document.getElementById("minutes").value = "00";
document.getElementById("seconds").value = "00";
startImage.src = "start.png";
}
startImage.addEventListener("click", function () {
if (document.getElementById("hours").value == 0 && document.getElementById("minutes").value == 0 && document.getElementById("seconds").value == 0) {
alert('시간이 입력되지 않았습니다.');
}
if (timerRunning) {
stopTimer();
} else {
startTimer();
}
});
resetButton.addEventListener("click", resetTimer);
function padWithZeroes(event) {
let value = event.target.value;
if (value.length === 1) {
event.target.value = value.padStart(2, '0');
} else if (value.length > 2) {
event.target.value = parseInt(value).toString();
}
}
document.getElementById("hours").addEventListener("input", padWithZeroes);
document.getElementById("minutes").addEventListener("input", padWithZeroes);
document.getElementById("seconds").addEventListener("input", padWithZeroes);
});
</script>
<br>
<br>
<br>
<br>
<footer>
<p >© 2024 Life Tracker.</p>
</footer>
</body>
</html>