-
Notifications
You must be signed in to change notification settings - Fork 0
/
TIMER.html
155 lines (121 loc) · 3.87 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TIMER</title>
<link rel="stylesheet" href="style4.css">
</head>
<header>
<nav>
<div class="openMenu"><i class="fa fa-bars"></i></div>
<ul class="mainMenu">
<li><a href="index.html">HOME</a></li>
<li><a href="WORLD CLOCK.html">CLOCK</a></li>
<li><a href="STOPWATCH.html">STOPWATCH</a></li>
</ul>
</nav>
</header>
<body>
<section>
<div class="clock">
<div class="container">
<div class="box">
<div class="hour">
<input type="number" id="hour" placeholder="HOUR" autocomplete="off" value=""></div>
</div>
<h2 class="dot">:</h2>
<div class="box">
<div class="minute">
<input type="number" id="minute" placeholder="MINUTES" autocomplete="off" value=""></div></div>
<h2 class="dot">:</h2>
<div class="box">
<div class="second">
<input type="number" id="second" placeholder="SECONDS" autocomplete="off" value=""></div>
<div class="box">
<div class="btn">
<button id="start">START</button>
<button id="stop">STOP</button>
<button id="reset">RESET</button>
<div class="stopsound">
<button id="stop-sound">Stop-Music</button>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<audio id="audio">
<source src="myaudio.mp3" type="audio/mpeg">
</audio>
</body>
<script>
var start = document.getElementById('start');
var stop = document.getElementById('stop');
var reset = document.getElementById('reset');
var stopsound = document.getElementById('stop-sound');
var h = document.getElementById("hour");
var m = document.getElementById("minute");
var s = document.getElementById("second");
var startTimer = null;
var audio = document.getElementById("audio");
stopsound.addEventListener('click',function(){
audio.pause();
audio.currentTime = 0;
});
start.addEventListener('click', function(){
if(startTimer === null && (h.value > 0 || m.value > 0 || s.value > 0)){
startTimer = setInterval(function() {
timer();
}, 1000);
h.disabled = true;
m.disabled = true;
s.disabled = true;
}
});
stop.addEventListener('click',function(){
clearInterval(startTimer);
startTimer = null;
h.disabled = true;
m.disabled = true;
s.disabled = true;
});
reset.addEventListener('click', function(){
h.value = 0;
m.value = 0;
s.value = 0;
stopInterval();
h.disabled = false;
m.disabled = false;
s.disabled = false;
});
function timer(){
if(h.value == 0 && m.value == 0 && s.value == 0){
h.value = 0;
m.value = 0;
s.value = 0;
stopInterval();
playAudio();
} else if(s.value != 0){
s.value--;
} else if(m.value != 0 && s.value == 0){
s.value = 59;
m.value--;
} else if(h.value != 0 && m.value == 0){
m.value = 60;
h.value--;
}
}
function stopInterval() {
clearInterval(startTimer);
startTimer = null;
h.disabled = false;
m.disabled = false;
s.disabled = false;
}
function playAudio(){
audio.play();
}
</script>
</html>