Skip to content

Instantly share code, notes, and snippets.

@luigircruz
Last active January 7, 2022 07:43
Show Gist options
  • Select an option

  • Save luigircruz/911fff4de91fa1a7db94c5174fcd3c63 to your computer and use it in GitHub Desktop.

Select an option

Save luigircruz/911fff4de91fa1a7db94c5174fcd3c63 to your computer and use it in GitHub Desktop.
// const options = {
// root: document.querySelector('.ct-inner-content'),
// rootMargin: '0px',
// threshold: 1.0
// }
const div = document.querySelector("#div_id");
const options = {}
let callback = (entries, observer) => {
entries.forEach(entry => {
// Add 'active' class if observation target is inside viewport
if (entry.intersectionRatio > 0) {
console.log(entry.target);
entry.target.classList.toggle("animate__animated", "animate__fadeInUp");
}
// Remove 'active' class otherwise
else {
entry.target.classList.remove("animate__animated", "animate__fadeInUp");
}
});
}
let observer = new IntersectionObserver(callback, options);
observer.observe(div);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment