Last active
August 19, 2021 01:08
-
-
Save mciastek/26411dca5b7f004381267f8a885f2c00 to your computer and use it in GitHub Desktop.
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
const intersectionObserver = new IntersectionObserver((entries, observer) => { | |
entries.forEach((entry) => { | |
if (entry.isIntersecting) { | |
// element is in viewport, do the stuff | |
// it's good to remove observer, | |
// if you don't need it any more | |
observer.unobserve(entry.target); | |
} | |
}); | |
}); | |
// get your elements, by class name '.js-item' | |
const elements = [...document.querySelectorAll('.js-item')]; | |
// start observing your elements | |
elements.forEach((element) => intersectionObserver.observe(element)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 💯