Skip to content

Instantly share code, notes, and snippets.

View lucasn-e's full-sized avatar

Lucas lucasn-e

  • poopie
  • Vienna
View GitHub Profile
@lucasn-e
lucasn-e / customIntersectionObserver.js
Last active November 22, 2024 20:32
Create a custom IntersectionObserver. Requires at least a target and a callback function.
export const customObserver = (settings = {}) => {
const { target, callback, options, margin, thresholds, immediate, caller, debug } = settings;
if (!caller && debug) console.warn("arg.caller TYPE:String unset - unable to trace call origin")
if (!target) return console.warn("arg.target TYPE:HTML:Node required" + (caller ? ' caller: ' + caller : ''));
if (typeof callback !== "function") return console.warn("arg.callback TYPE:Function required" + (caller ? ' caller: ' + caller : ''));
const usedOptions = options || {
root: null,
rootMargin: margin || "0px",
threshold: thresholds || 0,
};