-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
27 lines (23 loc) · 800 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
window.onload = () => {
const nav = document.querySelector("nav .nav-items");
const navBtn = document.querySelector(".nav-btn");
const allSections = document.querySelectorAll("section");
[...nav.children].forEach((item) => {
item.addEventListener("click", () => {
const href = item.getAttribute("data-href");
const section = document.querySelector(`#${href}`);
allSections.forEach((section) => {
section.classList.remove("active");
});
section.classList.add("active");
});
});
navBtn.addEventListener("click", () => {
navBtn.classList.toggle("active");
if ([...navBtn.classList].includes("active")) {
nav.parentElement.classList.add("active");
} else {
nav.parentElement.classList.remove("active");
}
});
};