An open API service indexing awesome lists of open source software.

https://github.com/hunghg255/scrollbar-block

A tiny library to block the scrollbar of the body element ✨
https://github.com/hunghg255/scrollbar-block

block lock package scrollbar

Last synced: 12 months ago
JSON representation

A tiny library to block the scrollbar of the body element ✨

Awesome Lists containing this project

README

          



logo


A tiny library to block the scrollbar of the body element ✨


NPM Version
NPM Downloads
Minizip
Contributors
License

## Live demo

[Live Demo](https://scrollbar-block.vercel.app/)

## Installation

[![NPM](https://nodei.co/npm/scrollbar-block.png?compact=true)](https://nodei.co/npm/scrollbar-block/)

## Install

```
npm i scrollbar-block@latest
```

## Use

```tsx
import React, { useEffect, useState } from 'react';
import { scrollbarBlock } from 'scrollbar-block';

function Modal({ open, children }) {
const dialogRef = React.useRef(null);
const unlockScrollbars = React.useRef(null);

useEffect(() => {
const dialogNode = dialogRef.current;
if (dialogNode) {
if (open) {
dialogNode.showModal();
unlockScrollbars.current = lockScrollbars();
} else {
dialogNode.close();
unlockScrollbars.current?.();
}
}
}, [open]);

return {children};
}
```

### About

Buy Me A Coffee

Gia Hung – [hung.hg](https://hung.thedev.id)