Skip to content

Instantly share code, notes, and snippets.

View lucasn-e's full-sized avatar

Lucas lucasn-e

  • PSPDFKit
  • Vienna
View GitHub Profile
@lucasn-e
lucasn-e / customIntersectionObserver.js
Created August 2, 2023 21:36
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,
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);