Last active
January 7, 2022 07:43
-
-
Save luigircruz/911fff4de91fa1a7db94c5174fcd3c63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // 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