UNPKG

@jhubbardsf/svelte-inview

Version:

A Svelte action that monitors an element enters or leaves the viewport or a parent element. Performant and efficient thanks to using Intersection Observer under the hood.

31 lines (30 loc) 827 B
export type Prefix = 'inview'; export type EventBase = 'change' | 'leave' | 'enter' | 'init'; export type Event = `${Prefix}_${EventBase}`; export type Options = { root?: HTMLElement | null; rootMargin?: string; threshold?: number | number[]; unobserveOnEnter?: boolean; }; export type Position = { x?: number; y?: number; }; type Direction = 'up' | 'down' | 'left' | 'right'; export type ScrollDirection = { vertical?: Direction; horizontal?: Direction; }; export type ObserverEventDetails = { inView: boolean; entry: IntersectionObserverEntry; scrollDirection: ScrollDirection; node: HTMLElement; observer: IntersectionObserver; }; export type LifecycleEventDetails = { node: HTMLElement; observer: IntersectionObserver; }; export {};