21 lines
813 B
JavaScript
21 lines
813 B
JavaScript
// ── Nav: scroll state & active link ───────────────────────────
|
|
(function () {
|
|
const header = document.getElementById('header');
|
|
const links = document.querySelectorAll('.nav-link');
|
|
const sections = document.querySelectorAll('section[id]');
|
|
const burger = document.getElementById('burger');
|
|
if (!header || !burger) return;
|
|
|
|
window.addEventListener('scroll', () => {
|
|
header.classList.toggle('scrolled', window.scrollY > 24 || burger.classList.contains('open'));
|
|
|
|
let current = '';
|
|
sections.forEach(s => {
|
|
if (window.scrollY >= s.offsetTop - 100) current = s.id;
|
|
});
|
|
links.forEach(l => {
|
|
l.classList.toggle('active', l.getAttribute('href') === '#' + current);
|
|
});
|
|
}, { passive: true });
|
|
})();
|