-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
187 lines (167 loc) · 5.99 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description"
content="countdowntimer, stopwatch, count, down, timer, time ,clock, watch ,stopper ,html ,css, javascript, miniproject ,mini, mini project, project">
<title>Countdown Timer</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<style>
* {
margin: 0;
padding: 0;
}
.main {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(#3AD0D0, #B8CD05);
}
.sub {
min-height: 50vh;
min-width: 50vw;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
border: 2px solid white;
border-radius: 50px;
background-color: rgba(255, 255, 255, 0.3);
backdrop-filter: blur(15px);
box-shadow: 1px 1px 10px rgba(255, 200, 200, 0.1);
}
.p {
font-size: 3rem;
padding: 20px;
}
.div1 {
margin: 15px;
font-size: large;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 2px;
}
.div2 {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 10px;
font-size: large;
}
input {
min-width: 6vw;
}
button {
padding: 10px;
background-color: #3ad0d098;
width: 80px;
}
</style>
</head>
<body>
<div class="main">
<div class="sub">
<p class="p">00 : 00 : 00</p>
<div class="div1">
<div>
<label for="hr">Hours : </label>
<input type="number" class="hr" placeholder="hours" max="24" min="0">
</div>
<div><label for="min">Minutes : </label>
<input type="number" class="min" placeholder="minutes" max="60" min="0">
</div>
<div><label for="sec">Seconds : </label>
<input type="number" class="sec" placeholder="seconds" max="60" min="0">
</div>
</div>
<div class="div2">
<button class="setTime">Set Time</button>
<button class="start">Start</button>
<button class="stop">Stop</button>
<button class="resume">Resume</button>
<button class="restart">Restart</button>
</div>
</div>
</div>
<script>
hr = document.querySelector(".hr");
min = document.querySelector(".min");
sec = document.querySelector(".sec");
p = document.querySelector(".p");
setTime = document.querySelector(".setTime");
start = document.querySelector(".start");
stop = document.querySelector(".stop");
resume = document.querySelector(".resume");
restart = document.querySelector(".restart");
function padStart(value) {
return value.toString().padStart(2, '0');
}
setTime.addEventListener("click", () => {
if ((hr.value > 24 || hr.value < 0) || (min.value > 60 || min.value < 0) || (sec.value > 24 || sec.value < 0)) {
alert("Enter proper time");
}
else {
p.innerText = `${hr.value.padStart(2, 0)} : ${min.value.padStart(2, 0)} : ${sec.value.padStart(2, 0)}`;
}
})
var sec11, min11, hr11, sec1, min1, hr1;
var intervalId;
function startTimer(sec, min, hr) {
sec1 = sec;
min1 = min;
hr1 = hr;
intervalId = setInterval(() => {
if (sec1 == 0 && min1 == 0 && hr1 == 0) {
alert("Time is up");
clearInterval(intervalId);
return;
}
if (sec1 == 0) {
if (min1 == 0) {
if (hr1 > 0) {
hr1--;
min1 = 59;
sec1 = 59;
}
} else {
min1--;
sec1 = 59;
}
} else {
sec1--;
}
p.innerText = `${hr1.toString().padStart(2, '0')} : ${min1.toString().padStart(2, '0')} : ${sec1.toString().padStart(2, '0')}`;
}, 1000);
}
start.addEventListener("click", () => {
sec1 = parseInt(sec.value) || 0;
min1 = parseInt(min.value) || 0;
hr1 = parseInt(hr.value) || 0;
clearInterval(intervalId); // Ensure any previous interval is cleared
startTimer(sec1, min1, hr1);
});
stop.addEventListener("click", () => {
sec11 = sec1;
min11 = min1;
hr11 = hr1;
clearInterval(intervalId);
});
resume.addEventListener("click", () => {
clearInterval(intervalId); // Ensure no multiple intervals run simultaneously
startTimer(sec11, min11, hr11);
});
restart.addEventListener("click", () => {
sec1 = parseInt(sec.value) || 0;
min1 = parseInt(min.value) || 0;
hr1 = parseInt(hr.value) || 0;
clearInterval(intervalId); // Ensure any previous interval is cleared
startTimer(sec1, min1, hr1);
});
</script>
</body>
</html>