react-remove-scroll-bar

Removes body scroll without content _shake_

MIT 20 个版本
安装
npm install react-remove-scroll-bar
yarn add react-remove-scroll-bar
pnpm add react-remove-scroll-bar
bun add react-remove-scroll-bar
README

react-remove-scroll-bar

npm bundle size downloads


v1+ for React 15, v2+ requires React 16.8+

Removes scroll bar (by setting overflow: hidden on body), and preserves the scroll bar "gap".

Read - it just makes scroll bar invisible.

Does nothing if scroll bar does not consume any space.

Usage

import {RemoveScrollBar} from 'react-remove-scroll-bar';

<RemoveScrollBar /> -> no scroll bar

The Right Border

To prevent content jumps position:fixed elements with right:0 should have additional classname applied. It will just provide a non-zero right, when it needed, to maintain the right "gap".

import {zeroRightClassName,fullWidthClassName, noScrollbarsClassName} from 'react-remove-scroll-bar';

// to set `right:0` on an element
<div className={zeroRightClassName} />

// to set `width:100%` on an element
<div className={fullWidthClassName} />

// to remove scrollbar from an element
<div className={noScrollbarsClassName} />

Size

500b after compression (excluding tslib).

Scroll-Locky

All code is a result of a react-scroll-locky refactoring.

Article

There is a medium article about preventing the body scroll - How to fight the scroll

License

MIT

版本列表
2.3.8 2024-12-15
2.3.7 2024-12-15
2.3.6 2024-03-14
2.3.5 2024-02-19
2.3.4 2022-10-12
2.3.3 2022-06-06
2.3.1 2022-05-01
2.3.0 2022-04-17
2.2.0 2021-02-10
2.1.1 2020-11-27
2.1.0 2020-04-16
2.0.0 2019-06-07
1.2.0 2019-06-04
1.1.5 2019-05-03
1.1.4 2019-03-02
1.1.3 2019-01-21
1.1.2 2019-01-18
1.1.1 2019-01-18
1.1.0 2019-01-18
1.0.0 2019-01-18