Answers for "toggle class on scroll"

0

toggle class on scroll

const images = document.querySelectorAll(".js-scroll");

observer = new IntersectionObserver((entries) => {
  entries.forEach((entry) => {
    if (entry.intersectionRatio > 0) {
      entry.target.classList.add("class-1");
    } else {
      entry.target.classList.remove("class-1");
    }
  });
});

images.forEach((image) => {
  observer.observe(image);
});

pure JavaScript
/*Rogi Network*/
/*+923022020318*/
/*roginetwork.com*/
Posted by: Guest on October-11-2021

Browse Popular Code Answers by Language