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)
})