-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.html
120 lines (108 loc) · 2.96 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Timer</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css"
/>
<style>
* {
font-family: cursive;
box-sizing: border-box;
}
body{
margin: 0;
height: 100vh;
display: grid;
place-items: center;
}
.stopwatch {
height: 350px;
width: 250px;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
padding: 20px;
border: 2px solid;
border-radius: 50px;
/* margin: auto; */
box-shadow: 10px 5px 50px gray;
position: relative;
}
#count {
border: inherit;
border-radius: 10px;
padding: 5px;
max-width: 120px;
text-align: center;
}
#start {
border: inherit;
border-radius: 10px;
padding: 5px 60px;
cursor: pointer;
}
#sets{
cursor: pointer;
}
.setting {
border: 2px solid;
padding: 5px;
border-radius: 10px;
position: absolute;
bottom: -50px;
background-color: aliceblue;
box-shadow: 1px 1px 6px rebeccapurple;
}
#speed {
width: 60px;
border: 2px solid;
border-radius: 10px;
text-align: center;
}
.show{
display: none;
}
</style>
</head>
<body>
<div class="stopwatch">
<input type="number" id="count" placeholder="Time( in sec.)" required />
<button id="start">Start</button>
<div id="timer">Timer</div>
<i class="fa-solid fa-gear" id="sets"></i>
<div class="setting show" id="setting">
<label for="speed">Set speed :</label>
<input type="number" name="speed" id="speed" placeholder="(1x)" />
</div>
</div>
<script>
let count = document.getElementById("count");
let btn = document.getElementById("start");
let timer = document.getElementById("timer");
let sets = document.getElementById("sets")
let setting = document.getElementById("setting");
sets.addEventListener("click", ()=>{
setting.classList.toggle("show")
})
btn.addEventListener("click", () => {
let speed = parseInt(document.getElementById("speed").value) || 1;
let t = parseInt(count.value)-1;
//-1 to match the pace of real timer as this will start after the delay of speed(1s default)
let countDown = setInterval(() => {
timer.innerText = t;
if (t <= 0) {
clearInterval(countDown);
timer.innerHTML = "<b>Time's Up</b>";
}
t--;
}, 1000 / speed);
console.log(speed);
});
</script>
</body>
</html>