@jirkasa/code-box
Version:
Showcase code samples on the web with a container that lets users select and display different samples.
36 lines (35 loc) • 1.44 kB
TypeScript
/** Component used to observe intersections between viewport and elements. */
declare class ViewportIntersectionObserver {
/** Instance of ViewportIntersectionObserver. */
private static instance;
/** Intersection observer. */
private observer;
/** Map of handlers that are called when intersection between viewport and element changes. */
private elements;
/**
* Creates new instance.
*/
private constructor();
/**
* Starts to observe intersection changes between passed element and viewport.
* @param element Element.
* @param handler Function to be called when intersection between element and viewport changes.
*/
static observe(element: Element, handler: (isIntersecting: boolean) => void): void;
/**
* Stops to observe intersection changes between passed element and viewport.
* @param element Element.
*/
static unobserve(element: Element): void;
/**
* Callback for IntersectionObserver (called when intersection between viewport and some observed element(s) changes).
* @param entries Intersection observer entries.
*/
private intersectionObserverCallback;
/**
* Returns instance of ViewportIntersectionObserver (this method should be used instead of constructor).
* @returns Instance of ViewportIntersectionObserver.
*/
private static getInstance;
}
export default ViewportIntersectionObserver;