index-main/assets/js/investigation.js
Julie Blanc aba8b4f37e
All checks were successful
Deploy / Deploy to Production (push) Successful in 5m17s
create template packages
2026-02-25 18:22:13 +01:00

32 lines
947 B
JavaScript

export function navInvestigation(){
const nav = document.getElementById('nav-investigation');
if (!nav) return;
const items = nav.querySelectorAll('li');
const headerOffset = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--h-header')) || 0;
const sections = Array.from(items).map(li => {
const href = li.querySelector('a')?.getAttribute('href');
const target = href ? document.querySelector(href) : null;
return { li, target };
}).filter(s => s.target);
const update = () => {
const scrollY = window.scrollY + headerOffset;
let current = sections[0];
for (const section of sections) {
if (section.target.offsetTop <= scrollY) {
current = section;
}
}
items.forEach(li => li.classList.remove('is-selected'));
if (current) current.li.classList.add('is-selected');
};
window.addEventListener('scroll', update, { passive: true });
update();
}