@blro/body-scroll-lock
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@blro/body-scroll-lock

Installation

::: code-group

npm install @blro/body-scroll-lock
pnpm add @blro/body-scroll-lock
yarn add @blro/body-scroll-lock

:::

Usage

You can lock the scroll by calling the disableBodyScroll function, and unlock the scroll by calling the enableBodyScroll function.

import { disableBodyScroll, enableBodyScroll } from "@blro/body-scroll-lock";

// Lock the scroll
disableBodyScroll();

// Unlock the scroll
enableBodyScroll();

If you call the disableBodyScroll function multiple times, you must call the enableBodyScroll function as many times as you called it to unlock the scroll.

import { disableBodyScroll, enableBodyScroll } from "@blro/body-scroll-lock";

// Lock twice
disableBodyScroll();

// Unlock once
enableBodyScroll();

// Scroll is still locked

// Unlock once more
enableBodyScroll();

// Now the scroll is unlocked

Or you can call the resetBodyScroll function to unlock the scroll regardless of the number of locks.

import {
  disableBodyScroll,
  enableBodyScroll,
  resetBodyScroll,
} from "@blro/body-scroll-lock";

// Lock twice
disableBodyScroll();
disableBodyScroll();

// Unlock once
enableBodyScroll();

// Scroll is unlocked

Readme

Keywords

none

Package Sidebar

Install

npm i @blro/body-scroll-lock

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

10.1 kB

Total Files

7

Last publish

Collaborators

  • blrog0319