this is a code to detect if the section which I'm scrolling right now is in the viewport or not. This code actually works only if I get onto any section and refresh the page, it doesn't work continuously when I scroll through the page.
var secArr = document.querySelectorAll('section');
secArr.forEach(onscroll = function (element) {
var bounding = element.getBoundingClientRect();
if (bounding.top <= 350.00 && bounding.top >= -270.00) {
if (!element.classList.contains("your-active-class")) {
element.setAttribute("class", "your-active-class");
}
}
else {
element.removeAttribute("class");
}
});