-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (28 loc) · 909 Bytes
/
script.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
const trigger = document.querySelector('.hamburger')
const target = document.querySelector('nav')
const navItems = document.querySelectorAll('.navbar-item')
const dropdownLinks = document.querySelectorAll('.dropdown-item a')
const handleClick = (e) => {
target.classList.toggle('active')
if (target.classList.contains('active')) {
document.body.style.overflow = 'hidden'
} else {
document.body.style.overflow = 'scroll'
}
}
const handleNavItemClick = (e) => {
if (window.innerWidth <= 768) {
e.stopPropagation()
e.currentTarget.classList.toggle('active')
}
}
const handleDropdownLinkClick = (e) => {
e.stopPropagation()
}
trigger.addEventListener('click', handleClick)
Array.from(navItems).forEach((navItem) =>
navItem.addEventListener('click', handleNavItemClick)
)
Array.from(dropdownLinks).forEach((link) =>
link.addEventListener('click', handleDropdownLinkClick)
)