Sync menu to scroll

This commit is contained in:
TheThomaas 2024-01-23 20:45:02 +01:00
parent 97e3239736
commit f85e6385fb
2 changed files with 31 additions and 1 deletions

View file

@ -1 +1,24 @@
document.documentElement.classList.replace('no-js', 'js'); document.documentElement.classList.replace('no-js', 'js');
const options = {
rootMargin: '0px 0px -50% 0px'
};
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
const id = entry.target.getAttribute("id");
if (entry.isIntersecting) {
document.querySelectorAll('[aria-current="page"]').forEach((z) => {
z.removeAttribute('aria-current', 'page')
});
const target = document.querySelector(`a[href="#${id}"]`);
if (target) {
document.querySelector(`a[href="#${id}"]`).setAttribute('aria-current', 'page');
}
}
});
},options);
/* document.querySelectorAll('[id^="section"]').forEach(function(section, i) { */
document.querySelectorAll('section').forEach(function(section, i) {
observer.observe(section);
});

View file

@ -6,6 +6,13 @@
@use './components/button'; @use './components/button';
@use './components/skip-link'; @use './components/skip-link';
:target:before {
content: "";
display: block;
height: 80px;
margin: -80px 0 0;
}
body { body {
--start: var(--primary-light); --start: var(--primary-light);
--end: var(--secondary); --end: var(--secondary);