<section class="1"></section>
<section class="2"></section>
<section class="3"></section>
<section class="4"></section>
<section class="5"></section>
const getId = (link) => link.getAttribute('href').replace('#', '')
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
document.querySelectorAll('.menu__link').forEach((link) => {
link.classList.toggle('menu__link--active', getId(link) === entry.target.id)
})
}
})
},
{
threshold: 0.4,
}
)
document.querySelectorAll('.section').forEach((section) => {
observer.observe(section)
})