-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo2.html
185 lines (152 loc) · 3.46 KB
/
demo2.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content=
"width=device-width" />
<meta http-equiv="X-UA-Compatible"
content="ie=edge" />
<link rel="stylesheet" href=
"https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<title>
Converting the hamburger icon
to X and vice versa
</title>
<style>
/* Styling the menu button */
.menu-btn {
position: absolute;
z-index: 3;
right: 35px;
top: 35px;
cursor: pointer;
transition: all 0.5s ease-out;
}
/* Styling the hamburger lines */
.menu-btn .btn-line {
width: 28px;
height: 3px;
margin: 0 0 5px 0;
background: black;
transition: all 0.5s ease-out;
}
/* Adding transform to the X */
.menu-btn.close {
transform: rotate(180deg);
}
/* Styling the three lines to make it an X */
.menu-btn.close .btn-line:nth-child(1) {
transform: rotate(45deg) translate(5px, 5px);
}
.menu-btn.close .btn-line:nth-child(2) {
opacity: 0;
}
.menu-btn.close .btn-line:nth-child(3) {
transform: rotate(-45deg) translate(7px, -6px);
}
/* Styling the position of the menu icon */
.menu {
position: fixed;
top: 0;
width: 100%;
opacity: 0.9;
visibility: hidden;
}
.menu.show {
visibility: visible;
}
/* Adding a transition delay
to the 4 items in the
navigation menu */
.nav-item:nth-child(1) {
transition-delay: 0.1s;
}
.nav-item:nth-child(2) {
transition-delay: 0.2s;
}
.nav-item:nth-child(3) {
transition-delay: 0.3s;
}
.nav-item:nth-child(4) {
transition-delay: 0.4s;
}
</style>
</head>
<body id="bg-img">
<header>
<div class="menu-btn">
<div class="btn-line"></div>
<div class="btn-line"></div>
<div class="btn-line"></div>
</div>
<nav class="menu">
<div class="menu-branding">
<div class="portrait">
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20200326201748/download312.png"
alt="" />
</div>
</div>
<ul class="menu-nav">
<li class="nav-item current">
<a href="#" class="nav-link">
HOME
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
ABOUT ME
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
MY WORK
</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">
CONTACT ME
</a>
</li>
</ul>
</nav>
</header>
<script>
// Select dom items
const menuBtn =
document.querySelector(".menu-btn");
const menu =
document.querySelector(".menu");
const menuNav =
document.querySelector(".menu-nav");
const menuBranding =
document.querySelector(".menu-branding");
const navItems =
document.querySelectorAll(".nav-item");
// Set the initial state of the menu
let showMenu = false;
menuBtn.addEventListener("click", toggleMenu);
function toggleMenu() {
if (!showMenu) {
menuBtn.classList.add("close");
menu.classList.add("show");
menuNav.classList.add("show");
menuBranding.classList.add("show");
navItems.forEach((item) =>
item.classList.add("show"));
// Reset the menu state
showMenu = true;
} else {
menuBtn.classList.remove("close");
menu.classList.remove("show");
menuNav.classList.remove("show");
menuBranding.classList.remove("show");
navItems.forEach((item) =>
item.classList.remove("show"));
// Reset the menu state
showMenu = false;
}
}
</script>
</body>
</html>