Created
May 4, 2021 06:28
-
-
Save webag/cd59d67ed09b015d930af9cb23ee6519 to your computer and use it in GitHub Desktop.
intersection anim entries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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