Created
August 2, 2023 21:36
-
-
Save lucasn-e/c079a26f280dbacfaa0cbf833c1768ab to your computer and use it in GitHub Desktop.
Create a custom IntersectionObserver. Requires at least a target and a callback function. Optionally you can return the observer as well if you desperately feel the need to save and reuse it. Or remove it. Or whatever else you feel like doing with it,
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
export const customObserver = (payload = {}) => { | |
if (!payload.callback || typeof payload.callback != "function") return; | |
if (!payload.target) return; | |
const usedOptions = payload.options || { | |
root: null, | |
rootMargin: payload.margin || "0px", | |
threshold: payload.thresholds || 0, | |
}; | |
const observer = new IntersectionObserver(payload.callback, usedOptions); | |
observer.observe(payload.target); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment