Skip to content

Instantly share code, notes, and snippets.

@gyeongseokKang
Created July 23, 2021 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyeongseokKang/af826f0a12e974e482660f6820890f3a to your computer and use it in GitHub Desktop.
Save gyeongseokKang/af826f0a12e974e482660f6820890f3a to your computer and use it in GitHub Desktop.
const targets = document.querySelectorAll(".fade-class");
const options = { root: null, threshold: 0.1, rootMargin: "-0px" };
const observer = new IntersectionObserver(function (entries, observer) {
entries.forEach((entry) => {
const container = entry.target;
if (entry.isIntersecting) {
container.classList.add("fade-in");
} else {
container.classList.remove("fade-in");
}
});
}, options);
targets.forEach((target) => {
observer.observe(target);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment