Please, how can I add a class to each section when scrolling to it my problem is that it happens only in the first section. I am a beginner and the problem is here
window.onscroll = function() {
allSections.forEach(section => {
let activeLink = document.querySelectorAll("nav a").forEach;
if(section.getBoundingClientRect().top >= -400 && section.getBoundingClientRect().top <= 150){
section.classList.add("your-active-class");
activeLink.classList.add("active-link");
}
else{
section.classList.remove("your-active-class");
activeLink.classList.remove("active-link");
}
})
}
code is here
https://codepen.io/mohamedtharwat000/pen/gOmwqqr