react-intersection-observer-ng
Version:
Monitor if a component is inside the viewport, using IntersectionObserver API
38 lines (37 loc) • 1.44 kB
TypeScript
import { IntersectionOptions } from './typings/types';
declare type Callback = (inView: boolean, intersection: IntersectionObserverEntry) => void;
export declare type ObserverInstance = {
callback: Callback;
element: Element;
inView: boolean;
observerId: string;
observer: IntersectionObserver;
thresholds: number[];
batch: boolean;
};
/**
* Monitor element, and trigger callback when element becomes inView
* @param element {HTMLElement}
* @param callback {Function} Called with inView
* @param options {Object} InterSection observer options
* @param options.threshold {Number} Number between 0 and 1, indicating how much of the element should be inView before triggering
* @param options.root {HTMLElement}
* @param options.rootMargin {String} The CSS margin to apply to the root element.
*/
export declare function observe(element: Element, callback: Callback, options?: IntersectionOptions): ObserverInstance | undefined;
/**
* Stop observing an element. If an element is removed from the DOM or otherwise destroyed,
* make sure to call this method.
* @param element {Element}
*/
export declare function unobserve(element: Element | null): void;
/**
* Destroy all IntersectionObservers currently connected
**/
export declare function destroy(): void;
declare const _default: {
observe: typeof observe;
unobserve: typeof unobserve;
destroy: typeof destroy;
};
export default _default;