-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.js
62 lines (51 loc) · 1.74 KB
/
home.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
const menuOpen = document.querySelector(".menu-open");
const menuClose = document.querySelector(".menu-close");
const navigation = document.querySelector(".navigation");
const links = document.querySelectorAll(".navigation a");
const sections = document.querySelectorAll(".section-a");
console.log("Observing sections:", sections);
// HAMBURGER MENU
menuOpen.addEventListener("click", function () {
navigation.classList.add("nav-open");
menuOpen.classList.add("menu-hide");
menuClose.classList.remove("menu-hide");
});
menuClose.addEventListener("click", function () {
navigation.classList.remove("nav-open");
menuClose.classList.add("menu-hide");
menuOpen.classList.remove("menu-hide");
});
// NAVIGATION SCROLL
links.forEach(function (link) {
link.addEventListener("click", function (e) {
e.preventDefault();
const targetId = link.getAttribute("href").substring(1);
const targetElement = document.getElementById(targetId);
targetElement.scrollIntoView({
behavior: "smooth",
block: "start",
});
navigation.classList.remove("nav-open");
menuClose.classList.add("menu-hide");
menuOpen.classList.remove("menu-hide");
});
});
// SECTION REVEAL ON SCROLL
const objOptions = {
root: null,
threshold: 0.1,
rootMargin: "0px",
};
const sectionObserver = new IntersectionObserver(callBackFunction, objOptions);
sections.forEach((section) => {
sectionObserver.observe(section);
});
function callBackFunction(entries) {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("section-visible");
} else {
entry.target.classList.remove("section-visible");
}
});
}