-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
78 lines (67 loc) · 2.25 KB
/
app.js
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
let img = document.createElement('img')
let btnNav = document.querySelector(".btn-nav")
img.src = './images/icon-hamburger.svg'
let nav = document.querySelector('.navigation')
let ul = document.querySelector(".nav-items")
let navItems = []
for (let navItem of document.querySelectorAll(".nav-li")) {
navItems.push(navItem)
}
let navMobileOpen = false
function checkMediaQuery() {
if (innerWidth <= 800) {
btnNav.classList.add("hide")
navItems.forEach(item => {
item.classList.remove("nav-items")
item.classList.add("hide")
})
nav.appendChild(img)
if (!navMobileOpen) {
displayNav()
}
}
else {
btnNav.classList.remove("hide")
navItems.forEach(item => {
item.classList.remove("hide")
item.classList.add("nav-items")})
img.remove()
ul.classList.remove("nav-items-mobile")
ul.classList.add("nav-items")
navItems.forEach(item => {
item.classList.add("hide")
item.classList.remove("mobileNav")
})
}
}
function displayNav() {
navMobileOpen = !navMobileOpen
if (!navMobileOpen) {
img.src = './images/icon-close.svg'
navItems.forEach(item => {
item.classList.remove("hide")
item.classList.add("mobileNav")
})
ul.classList.add("nav-items-mobile")
ul.classList.remove("nav-items")
document.querySelector('.upper-body').classList.add("bg-dark")
document.querySelector('.main-body-two').classList.add("bg-dark-2")
document.querySelector('.lower-body').classList.add("bg-dark")
}
if (navMobileOpen) {
img.src = './images/icon-hamburger.svg'
ul.classList.remove("nav-items-mobile")
ul.classList.add("nav-items")
navItems.forEach(item => {
item.classList.add("hide")
item.classList.remove("mobileNav")
})
document.querySelector('.upper-body').classList.remove("bg-dark")
document.querySelector('.main-body-two').classList.remove("bg-dark-2")
document.querySelector('.lower-body').classList.remove("bg-dark")
}
}
window.addEventListener("resize", checkMediaQuery)
img.addEventListener("click", displayNav)
checkMediaQuery()
displayNav()