fn
useScrollLock
v0.0.15testeddemoLock scrolling of an element by toggling `overflow: hidden`, preserving the element's prior inline overflow and handling iOS `touchmove`. Returns a writable boolean ref — set it to lock/unlock, read it for state.
Example
ts
const el = useTemplateRef<HTMLElement>('el');
const isLocked = useScrollLock(el);
isLocked.value = true; // lock
isLocked.value = false; // unlockDemo
Loading demo…
Signature
ts
export function useScrollLock(
element: MaybeComputedElementRef,
initialState = false,
options: UseScrollLockOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
element | MaybeComputedElementRef | The element (or template ref / getter) to lock. |
initialState? | boolean | Whether the element starts locked. Defaults to `false`. |
options? | UseScrollLockOptions | Configurable `window` / `navigator` (mainly for SSR & testing). |
Returns
UseScrollLockReturnA writable boolean ref; `true` while locked.