Skip to content

Instantly share code, notes, and snippets.

@webag
Created May 4, 2021 06:28
Show Gist options
  • Save webag/cd59d67ed09b015d930af9cb23ee6519 to your computer and use it in GitHub Desktop.
Save webag/cd59d67ed09b015d930af9cb23ee6519 to your computer and use it in GitHub Desktop.
intersection anim entries
/* Anim Observer BEGIN */
document.addEventListener("DOMContentLoaded", function(event) {
const elements = document.querySelectorAll('.anim');
const options = {
rootMargin: '0px 0px',
threshold: 1
}
const callback = (entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animated');
observer.unobserve(entry.target);
} else {
//entry.target.classList.remove('animated');
}
});
}
const observer = new IntersectionObserver(callback,options);
elements.forEach(element => {
observer.observe(element);
});
});
/* Anim Observer END */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment