-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
55 lines (48 loc) · 1.53 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const hamburger = document.querySelector(".hamburger");
const navMenu = document.querySelector(".nav-menu");
const homePage = document.querySelector(".home-page");
hamburger.addEventListener("click", () => {
hamburger.classList.toggle("active");
navMenu.classList.toggle("active");
});
document.querySelectorAll(".nav-link").forEach((n) =>
n.addEventListener("click", () => {
hamburger.classList.remove("active");
navMenu.classList.remove("active");
})
);
// INTERSECTION OBSERVER API
const homeCall = (entries, observer) => {
const [entry] = entries;
console.log(entry);
const navBar = document.querySelector(".navbar");
const navLink = document.querySelectorAll(".nav-link");
const icon = document.querySelector(".icon-i");
const bar = document.querySelectorAll(".bar");
if (!entry.isIntersecting) {
navBar.style.background = "white";
navLink.forEach((nav, i) => {
nav.classList.add("color-b");
nav.classList.remove("color-w");
bar[i].classList.add("color-b");
});
icon.classList.add("color-b");
icon.classList.remove("color-w");
} else {
navBar.style.border = "none";
navBar.style.background = "transparent";
navLink.forEach((nav) => {
nav.classList.add("color-w");
nav.classList.remove("color-b");
});
icon.classList.add("color-w");
icon.classList.remove("color-b");
}
};
let homeOpt = {
root: null,
rootMargin: "0px",
threshold: 0.1,
};
const observeHomePage = new IntersectionObserver(homeCall, homeOpt);
observeHomePage.observe(homePage);