-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
94 lines (75 loc) · 2.37 KB
/
Copy pathscript.js
File metadata and controls
94 lines (75 loc) · 2.37 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
const header = document.querySelector(".site-header");
const menuToggle = document.querySelector(".menu-toggle");
const navigation = document.querySelector(".nav-links");
const navigationLinks = document.querySelectorAll(".nav-links a");
const revealElements = document.querySelectorAll(".reveal");
const sections = document.querySelectorAll("main section[id]");
const yearElement = document.querySelector("#current-year");
function updateHeader() {
if (window.scrollY > 30) {
header.classList.add("scrolled");
} else {
header.classList.remove("scrolled");
}
}
function closeMenu() {
menuToggle.classList.remove("active");
navigation.classList.remove("open");
menuToggle.setAttribute("aria-expanded", "false");
document.body.classList.remove("menu-open");
}
function toggleMenu() {
const isOpen = navigation.classList.toggle("open");
menuToggle.classList.toggle("active", isOpen);
menuToggle.setAttribute("aria-expanded", String(isOpen));
document.body.classList.toggle("menu-open", isOpen);
}
function updateActiveNavigation() {
let currentSection = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop - 150;
if (window.scrollY >= sectionTop) {
currentSection = section.getAttribute("id");
}
});
navigationLinks.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href") === `#${currentSection}`) {
link.classList.add("active");
}
});
}
menuToggle.addEventListener("click", toggleMenu);
navigationLinks.forEach((link) => {
link.addEventListener("click", closeMenu);
});
window.addEventListener("scroll", () => {
updateHeader();
updateActiveNavigation();
});
window.addEventListener("resize", () => {
if (window.innerWidth > 820) {
closeMenu();
}
});
const revealObserver = new IntersectionObserver(
(entries, observer) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) {
return;
}
entry.target.classList.add("visible");
observer.unobserve(entry.target);
});
},
{
threshold: 0.12
}
);
revealElements.forEach((element) => {
revealObserver.observe(element);
});
yearElement.textContent = new Date().getFullYear();
updateHeader();
updateActiveNavigation();