react-remove-scroll-bar

中文文档
2.3.8发布于 2024/12/15MITTypeScriptESM + CJS近 30 天下载 3亿

Removes body scroll without content shake

原始使用文档

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

版本与发布记录

react-remove-scroll-bar 共发布 20 个版本,首次发布于 2019/01/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.3.8latest2024/12/151.9 年前
2.3.72024/12/151.9 年前
2.3.62024/03/142 年前
2.3.52024/02/192 年前
2.3.42022/10/134 年前
2.3.32022/06/064 年前

关于 react-remove-scroll-bar 的常见问题

react-remove-scroll-bar 是什么?

Removes body scroll without content shake

如何安装 react-remove-scroll-bar?

在项目目录运行 npm install react-remove-scroll-bar,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

react-remove-scroll-bar 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

react-remove-scroll-bar 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

react-remove-scroll-bar 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

react-remove-scroll-bar 可以商用吗?

react-remove-scroll-bar 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

react-remove-scroll-bar 的下载量有多少?

根据 npm 官方下载统计,react-remove-scroll-bar 在 2026/10/07 – 2026/11/05 这 30 天内被下载 302,852,838 次,日均约 10,095,095 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

react-remove-scroll-bar 还在维护吗?

最新版本 2.3.8 发布于 2024/12/15(1.9 年前);至今共发布 20 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/01/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。