UNPKG

@dvcol/common-utils

Version:

Typescript library for common utility functions and constants

56 lines (54 loc) 1.59 kB
type LockedElement = HTMLElement & { dataset: DOMStringMap & { locked?: string; offsetX?: string; offsetY?: string; }; }; type ScrollContainer = { scrollTo: (x: number, y: number) => void; }; type UseMobileScrollLock = { /** * Locks the scroll of the target element by setting the scroll position to fixed. * * @returns True if the scroll was locked, false if the scroll was already locked. */ lock: () => boolean; /** * Unlocks the scroll of the target element by restoring the scroll position to the original state. * * @returns True if the scroll was unlocked, false if the scroll was not locked. */ unlock: () => boolean; /** * The target element to lock the scroll. * * @default document.body */ target: LockedElement; /** * The number of locks that are active. */ count: number; /** * Whether the scroll is locked. */ locked: boolean; /** * The scroll offset of the target element. */ offset: { x: number; y: number; }; }; /** * Locks the scroll of the target element by setting the scroll position to fixed. * * Note: Removing the lock will restore the scroll position to the original state, regardless of the amount of locks. * @param target * @param container */ declare const useMobileScrollLock: (target?: LockedElement, container?: ScrollContainer) => UseMobileScrollLock; export { type LockedElement, type ScrollContainer, type UseMobileScrollLock, useMobileScrollLock };