-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountdownTimer.html
More file actions
251 lines (222 loc) · 7.73 KB
/
CountdownTimer.html
File metadata and controls
251 lines (222 loc) · 7.73 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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modern Countdown Timer</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', sans-serif;
}
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
color: #fff;
}
.timer-container {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(15px);
border-radius: 20px;
padding: 2rem;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(255, 255, 255, 0.2);
text-align: center;
}
.timer-display {
position: relative;
width: 250px;
height: 250px;
margin: 0 auto 2rem;
}
svg {
transform: rotate(-90deg);
}
.circle-bg {
fill: none;
stroke: rgba(255, 255, 255, 0.1);
stroke-width: 8;
}
.circle-progress {
fill: none;
stroke: #00ddeb;
stroke-width: 8;
stroke-linecap: round;
transition: stroke-dashoffset 0.1s linear;
}
.time {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 3rem;
font-weight: 300;
text-shadow: 0 0 15px rgba(255, 255, 255, 0.3);
}
.controls {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.input-group {
display: flex;
gap: 0.5rem;
justify-content: center;
}
input {
width: 60px;
padding: 0.5rem;
border: none;
border-radius: 10px;
background: rgba(255, 255, 255, 0.1);
color: #fff;
text-align: center;
font-size: 1rem;
}
input:focus {
outline: none;
background: rgba(255, 255, 255, 0.2);
}
.btn-group {
display: flex;
gap: 1rem;
justify-content: center;
}
button {
padding: 0.7rem 1.5rem;
border: none;
border-radius: 25px;
background: rgba(255, 255, 255, 0.1);
color: #fff;
cursor: pointer;
transition: all 0.3s ease;
font-size: 1rem;
}
button:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
}
button.active {
background: #00ddeb;
}
@media (max-width: 480px) {
.timer-container { padding: 1.5rem; }
.time { font-size: 2.5rem; }
.timer-display { width: 200px; height: 200px; }
}
</style>
</head>
<body>
<div class="timer-container">
<div class="timer-display">
<svg width="250" height="250">
<circle class="circle-bg" cx="125" cy="125" r="115"></circle>
<circle class="circle-progress" cx="125" cy="125" r="115" stroke-dasharray="723" stroke-dashoffset="0"></circle>
</svg>
<div class="time" id="time">00:00:00</div>
</div>
<div class="controls">
<div class="input-group">
<input type="number" id="hours" min="0" max="99" placeholder="HH">
<input type="number" id="minutes" min="0" max="59" placeholder="MM">
<input type="number" id="seconds" min="0" max="59" placeholder="SS">
</div>
<div class="btn-group">
<button id="startPause">Start</button>
<button id="reset">Reset</button>
</div>
</div>
</div>
<script>
const timeElement = document.getElementById('time');
const hoursInput = document.getElementById('hours');
const minutesInput = document.getElementById('minutes');
const secondsInput = document.getElementById('seconds');
const startPauseBtn = document.getElementById('startPause');
const resetBtn = document.getElementById('reset');
const circleProgress = document.querySelector('.circle-progress');
let totalSeconds = 0;
let remainingSeconds = 0;
let timer = null;
let isRunning = false;
const fullDashArray = 723; // Circumference of circle (2 * π * r)
function updateDisplay() {
const hours = Math.floor(remainingSeconds / 3600).toString().padStart(2, '0');
const minutes = Math.floor((remainingSeconds % 3600) / 60).toString().padStart(2, '0');
const seconds = (remainingSeconds % 60).toString().padStart(2, '0');
timeElement.textContent = `${hours}:${minutes}:${seconds}`;
const progress = (remainingSeconds / totalSeconds) * fullDashArray;
circleProgress.style.strokeDashoffset = fullDashArray - progress;
}
function startTimer() {
if (!isRunning && remainingSeconds > 0) {
timer = setInterval(() => {
remainingSeconds--;
updateDisplay();
if (remainingSeconds <= 0) {
clearInterval(timer);
isRunning = false;
startPauseBtn.textContent = 'Start';
startPauseBtn.classList.remove('active');
playSound();
}
}, 1000);
isRunning = true;
startPauseBtn.textContent = 'Pause';
startPauseBtn.classList.add('active');
}
}
function pauseTimer() {
if (isRunning) {
clearInterval(timer);
isRunning = false;
startPauseBtn.textContent = 'Start';
startPauseBtn.classList.remove('active');
}
}
function resetTimer() {
clearInterval(timer);
isRunning = false;
remainingSeconds = totalSeconds;
startPauseBtn.textContent = 'Start';
startPauseBtn.classList.remove('active');
updateDisplay();
}
function setTimer() {
const hours = parseInt(hoursInput.value) || 0;
const minutes = parseInt(minutesInput.value) || 0;
const seconds = parseInt(secondsInput.value) || 0;
totalSeconds = hours * 3600 + minutes * 60 + seconds;
remainingSeconds = totalSeconds;
updateDisplay();
}
function playSound() {
const audio = new Audio('https://www.soundjay.com/buttons/beep-01a.mp3');
audio.play().catch(e => console.log('Audio playback failed:', e));
}
startPauseBtn.addEventListener('click', () => {
if (!isRunning && totalSeconds === 0) setTimer();
isRunning ? pauseTimer() : startTimer();
});
resetBtn.addEventListener('click', () => {
resetTimer();
hoursInput.value = '';
minutesInput.value = '';
secondsInput.value = '';
totalSeconds = 0;
});
[hoursInput, minutesInput, secondsInput].forEach(input => {
input.addEventListener('change', () => {
if (!isRunning) setTimer();
});
});
// Initial setup
updateDisplay();
</script>
</body>
</html>