2026-02-23 14:02:26 +01:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|