Created
March 25, 2023 16:54
-
-
Save aniketchanana/69866cc2b2cbe6cc50b63bcb35596996 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 element = document.querySelector(ELEMENT_SELECTOR); | |
const parentElement = document.querySelector(PARENT_ELEMENT_SELECTOR); | |
const observer = new IntersectionObserver( | |
(entries: any) => { | |
/** | |
* Callback will run when observed element intersect with given root | |
*/ | |
}, | |
{ | |
root: parentElement, // if passed null take document as root | |
rootMargin: "0px", // give 0px margin to container value is given like CSS margin but it is not CSS | |
threshold: 0.5, // when 50% of the observed element is intersected | |
} | |
); | |
observer.observe(element); | |
// if you want to remove observer | |
observer.unobserve(element); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment