Skip to content

Instantly share code, notes, and snippets.

@rhysd
Last active May 12, 2023 01:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rhysd/cb83ab616211f271bc73186416a30811 to your computer and use it in GitHub Desktop.
Save rhysd/cb83ab616211f271bc73186416a30811 to your computer and use it in GitHub Desktop.
// https://wicg.github.io/IntersectionObserver/#intersection-observer-private-slots
/*
callback IntersectionObserverCallback = void (sequence<IntersectionObserverEntry> entries, IntersectionObserver observer)
[Constructor(IntersectionObserverCallback callback, optional IntersectionObserverInit options),
Exposed=Window]
interface IntersectionObserver {
readonly attribute Element? root;
readonly attribute DOMString rootMargin;
readonly attribute sequence<double> thresholds;
void observe(Element target);
void unobserve(Element target);
void disconnect();
sequence<IntersectionObserverEntry> takeRecords();
};
[Constructor(IntersectionObserverEntryInit intersectionObserverEntryInit)]
interface IntersectionObserverEntry {
readonly attribute DOMHighResTimeStamp time;
readonly attribute DOMRectReadOnly rootBounds;
readonly attribute DOMRectReadOnly boundingClientRect;
readonly attribute DOMRectReadOnly intersectionRect;
readonly attribute double intersectionRatio;
readonly attribute Element target;
};
dictionary IntersectionObserverEntryInit {
required DOMHighResTimeStamp time;
required DOMRectInit rootBounds;
required DOMRectInit boundingClientRect;
required DOMRectInit intersectionRect;
required double intersectionRatio;
required Element target;
};
dictionary IntersectionObserverInit {
Element? root = null;
DOMString rootMargin = "0px";
(double or sequence<double>) threshold = 0;
};
*/
interface Bounds {
readonly height: number;
readonly width: number;
readonly top: number;
readonly left: number;
readonly right: number;
readonly bottom: number;
}
interface IntersectionObserverEntry {
readonly time: number;
readonly rootBounds: Bounds;
readonly boundingClientRect: Bounds;
readonly intersectionRect: Bounds;
readonly intersectionRatio: number;
readonly target: Element;
}
type IntersectionObserverCallback = (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void;
interface IntersectionObserverInit {
root?: Element | null;
rootMargin?: string;
threshold?: number;
}
declare class IntersectionObserver {
readonly root: Element | null;
readonly rootMargin: string;
readonly thresholds: number[];
constructor(callback: IntersectionObserverCallback, options?: IntersectionObserverInit);
observe(target: Element): void;
unobserve(target: Element): void;
disconnect(): void;
takeRecords(): IntersectionObserverEntry[];
}
@Judejvlr
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment