-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (36 loc) · 1.2 KB
/
Copy pathscript.js
File metadata and controls
42 lines (36 loc) · 1.2 KB
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
const year = document.querySelector("#year");
if (year) {
year.textContent = new Date().getFullYear();
}
const revealItems = document.querySelectorAll(".reveal");
if ("IntersectionObserver" in window) {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("in-view");
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.16 }
);
revealItems.forEach((item) => observer.observe(item));
} else {
revealItems.forEach((item) => item.classList.add("in-view"));
}
const navLinks = Array.from(document.querySelectorAll(".nav a"));
const sections = navLinks
.map((link) => document.querySelector(link.getAttribute("href")))
.filter(Boolean);
const setActiveNav = () => {
const current = sections.reduce((active, section) => {
const box = section.getBoundingClientRect();
return box.top <= 110 ? section : active;
}, null);
navLinks.forEach((link) => {
link.classList.toggle("active", Boolean(current) && link.getAttribute("href") === `#${current.id}`);
});
};
window.addEventListener("scroll", setActiveNav, { passive: true });
setActiveNav();