@numiko/scroll-lock
v1.4.3
Published
Scroll Lock
Readme
Scroll Lock
A lightweight utility to lock and unlock page scrolling. Prevents background scroll when modals, drawers, or overlays are open, while preserving the user's scroll position.
Features
- Lock and unlock page scrolling programmatically
- Preserves scroll position when unlocking
- Supports custom scroll containers (defaults to
document.body) - Uses plain CSS styles for scroll locking
- Lightweight with zero dependencies
Installation
npm install @numiko/scroll-lockUsage
import { scrollLock } from '@numiko/scroll-lock';
// Create a scroll lock instance (defaults to document.body)
const lock = scrollLock();
// Disable scrolling
lock.disableScroll();
// Enable scrolling (restores previous scroll position)
lock.enableScroll();
// Check if scrolling is currently locked
lock.getIsLocked(); // true or falseYou can also pass a custom element to lock scrolling on:
const customLock = scrollLock(document.querySelector('[data-js-lock-container]'));API
See documentation for more detail on how to use the package.
