UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

89 lines 3.18 kB
export default TinyAfterScrollWatcher; /** * - Function with no arguments and no return value */ export type FnData = (() => void); /** * A function that handles a scroll event. * It receives a standard `Event` object when a scroll occurs. */ export type OnScrollFunc = (ev: Event) => void; /** * @typedef {(() => void)} FnData - Function with no arguments and no return value */ /** * A function that handles a scroll event. * It receives a standard `Event` object when a scroll occurs. * * @typedef {(ev: Event) => void} OnScrollFunc */ /** * A scroll tracker that queues functions to be executed * after the user stops scrolling a specific element or the window. */ declare class TinyAfterScrollWatcher { /** * @param {Element|Window} scrollTarget - The element or window to track scrolling on * @param {number} [inactivityTime=100] - Time in milliseconds to wait after scroll ends before executing the queue * @throws {TypeError} If scrollTarget is not a valid Element or Window * @throws {TypeError} If inactivityTime is not a positive number */ constructor(scrollTarget?: Element | Window, inactivityTime?: number); _checkTimer: () => void; /** * Sets a new inactivity time. * Must be a positive number (in milliseconds). * @param {number} value * @throws {Error} If value is not a positive number */ set inactivityTime(value: number); /** * Gets the current inactivity time in milliseconds. * @returns {number} */ get inactivityTime(): number; /** * Adds a function to be executed after scroll has stopped. * The scroll is considered "stopped" after the configured inactivity time. * * @param {() => void} fn - A function to execute once scrolling has stopped. * @throws {TypeError} If the argument is not a function. */ doAfterScroll(fn: () => void): void; lastScrollTime: number | undefined; /** * Registers a function to run once after scrolling has stopped, * before any afterScrollQueue functions. * * @param {FnData} fn - A function to execute after scroll stop. * @throws {TypeError} If the argument is not a function. */ onStop(fn: FnData): void; /** * Removes a previously registered onStop function. * * @param {FnData} fn - The function to remove. * @throws {TypeError} If the argument is not a function. */ offStop(fn: FnData): void; /** * Registers an external scroll listener on the tracked element. * * @param {OnScrollFunc} fn - The scroll listener to add * @throws {TypeError} If the argument is not a function. */ onScroll(fn: OnScrollFunc): void; /** * Removes a previously registered scroll listener from the tracked element. * * @param {OnScrollFunc} fn - The scroll listener to remove * @throws {TypeError} If the argument is not a function. */ offScroll(fn: OnScrollFunc): void; /** * Destroys the watcher by removing internal listeners and clearing data. */ destroy(): void; #private; } //# sourceMappingURL=TinyAfterScrollWatcher.d.mts.map