How to show content after page has been reloaded when I reveal sections?

Viewed 52

Hi I'm trying to show content after the page has been scrolled and revealed. This is the code, should I make a function to check if the page has been loaded already then take off the animation? Thanks.

const allSections = document.querySelectorAll(".section");

const revealSection = function (entries, observer) {
  const [entry] = entries;

  if (!entry.isIntersecting) return;

  entry.target.classList.remove("section--hidden");
  observer.unobserve(entry.target);
};

const sectionObserver = new IntersectionObserver(revealSection, {
  root: null,
  threshold: 0.15,
});

allSections.forEach(function (section) {
  sectionObserver.observe(section);
  section.classList.add("section--hidden");
});
0 Answers
Related