-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (25 loc) · 971 Bytes
/
script.js
File metadata and controls
30 lines (25 loc) · 971 Bytes
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
let menuIcon = document.querySelector("#menu-icon");
let navbar = document.querySelector(".navbar");
let sections = document.querySelectorAll("section");
let navLinks = document.querySelectorAll("header nav a");
const observerOptions = {
threshold: 0.3, // Aktiviert, wenn 30% der Sektion sichtbar sind
};
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
const id = entry.target.getAttribute("id");
navLinks.forEach((link) => {
// Prüft ob der Link-Hash exakt der Sektions-ID entspricht
const href = link.getAttribute("href");
const isTarget = href.endsWith(`#${id}`) || href === `sites/${id}.html`;
link.classList.toggle("active", isTarget);
});
}
});
}, observerOptions);
sections.forEach((section) => observer.observe(section));
menuIcon.onclick = () => {
menuIcon.classList.toggle("bx-x");
navbar.classList.toggle("active");
};