Created
November 16, 2022 12:09
-
-
Save anova/19a0403c6d163b003a45c2ced3422878 to your computer and use it in GitHub Desktop.
creates an Intersection Observer.
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
/** @return IntersectionObserver */ | |
function createObserver(p_threshold) { | |
return new IntersectionObserver( | |
(entries) => { | |
entries.forEach((/** @type IntersectionObserverEntry */ entry) => { | |
if (entry.isIntersecting) { | |
const eventIntersecting = new CustomEvent("intersecting"); | |
entry.target.dispatchEvent(eventIntersecting); | |
return; | |
} | |
const eventNotIntersecting = new CustomEvent("not-intersecting"); | |
entry.target.dispatchEvent(eventNotIntersecting); | |
}); | |
}, | |
{ | |
threshold: p_threshold, | |
} | |
); | |
} | |
export { | |
createObserver | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note to myself: if "muted" attribute is absent, autoplay blocked.