-
Notifications
You must be signed in to change notification settings - Fork 0
/
counter.html
110 lines (96 loc) · 2.53 KB
/
counter.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
<!DOCTYPE html>
<html lang="en">
<style>
body {
background-color: orange;
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
}
#counter {
font-size: 2rem;
}
.container {
width: 40vh;
height: 40vh;
display: flex;
flex-direction: column;
padding: 0px 8px;
transition: all 0.5s;
border-radius: 8px;
}
.center {
display: flex;
justify-content: center;
align-items: center;
}
.text-center {
text-align: center;
}
.outer-container {
display: flex;
width: 100vw;
height: 100vh;
justify-content: center;
align-items: center;
}
button {
padding: 10px 20px;
background-color: blue;
color: white;
border: none;
/* circle */
border-radius: 50%;
width: 50px;
height: 50px;
cursor: pointer;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.5);
}
button:hover {
background-color: rgb(63, 63, 226);
}
.button-group {
display: flex;
justify-content: center;
align-items: center;
/* space between */
gap: 10px;
}
</style>
<body>
<div class="outer-container center">
<div class="container center">
<h4 class="text-center">Counter</h4>
<h2 class="text-center" id="counter">0</h2>
<div class="button-group center">
<button id="increase">+</button>
<button id="decrease">-</button>
</div>
</div>
</div>
<script>
const increaseButton = document.getElementById('increase');
const decreaseButton = document.getElementById('decrease');
// add event listener to button
increaseButton.addEventListener('click', increase);
decreaseButton.addEventListener('click', decrease);
function increase() {
// get counter by id
const counter = document.getElementById('counter');
// get counter value
let value = parseInt(counter.innerText);
// increase value
value++;
// set counter value
counter.innerText = value;
}
function decrease() {
const counter = document.getElementById('counter');
let value = parseInt(counter.innerText);
value--;
counter.innerText = value;
}
</script>
</body>
</html>