-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
122 lines (97 loc) · 2.55 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>stopwatch</title>
<style>
*{
box-sizing: border-box;
margin: 0;
padding: 0;
}
body{
background-color: teal;
height: 50vh;
width: 60vw;
}
.container{
position: absolute;
border: 1px solid black;
height: 500px;
width:50%;
margin: 25%;
text-align: center;
border-radius: 20px;
box-shadow: 0px 0px 16px;
background-color: wheat;
padding: 70px;
justify-content: center;
margin-top: 100px;
margin-right: 30px;
font-size: 2.5rem;
}
button{
height: 60px;
font-size: 1.5rem;
width: 100px;
border-radius: 5px;
color:rgb(21, 185, 185);
}
button:hover{
background-color:teal;
}
</style>
</head>
<body>
<div class="container">
<h1>Stopwatch</h1>
<br>
<div class="display">00hr : 00min : 00s : 00ms </div>
<br>
<button onClick="start()">Start</button>
<button onClick="pouse()">Pause</button>
<button onClick="reset()">Reset</button>
</div>
</body>
</html>
<script>
let second=0
let minute=0
let hours=0
let milisecond=0
let time;
let display_timer = document.querySelector(".display")
function start(){
time= setInterval(()=>{
milisecond+=100;
if(milisecond==1000){
milisecond=0
second+=1;
}
if(second==60){
second=0
minute++;
}
if(minute==60){
minute=0
hours++;
}
display_timer.innerText=formatTime(hours)+" : " + formatTime(minute)+ " : "+ formatTime(second)+ " : " + formatTime(milisecond);
},100)
}
function pouse(){
clearInterval(time)
}
function reset(){
second=0
minute=0
hours=0
milisecond=0
display_timer.innerText="00hr : 00min : 00s : 00ms"
}
// when left side timer will be 0 like hour , minute then next zero should be work in timer like sec , milisec
function formatTime(time){
return (time<10 ? "0" + time : time);
}
</script>