react-scrolllock

Prevent scroll on the body when component is mounted.

react-scrolllock downloads react-scrolllock version react-scrolllock license

react-scrolllock类似的npm包:

npm下载趋势

3 年
🌟 在 react-scrolllock 的 README.md 中显示实时使用量图表,只需复制下面的代码。
## Usage Trend
[![Usage Trend of react-scrolllock](https://npm-compare.com/img/npm-trend/THREE_YEARS/react-scrolllock.png)](https://npm-compare.com/react-scrolllock#timeRange=THREE_YEARS)

Cumulative GitHub Star Trend

🌟 在 react-scrolllock 的 README.md 中显示 GitHub stars 趋势图表,只需复制下面的代码。
## GitHub Stars Trend
[![GitHub Stars Trend of react-scrolllock](https://npm-compare.com/img/github-trend/react-scrolllock.png)](https://npm-compare.com/react-scrolllock)

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
react-scrolllock120,588467-376 年前MIT

react-scrolllock的README

React Scroll Lock

Prevent scroll on the <body /> when a component is mounted.

Install

yarn add react-scrolllock

Usage

import ScrollLock, { TouchScrollable } from 'react-scrolllock';

class Modal extends Component {
  state = { lockScroll: false }
  render() {
    return (
      <div>
        ...
        // the lock accepts a single child element, which supports touch-scrolling.
        <ScrollLock>
          <ElementWithScrollableContent>...</ElementWithScrollableContent>
        </ScrollLock>

        // if your app structure doesn't allow wrapping like above, the `TouchScrollable`
        // component is exposed as a named export.
        <ScrollLock />
        <TouchScrollable>
          <ElementWithScrollableContent>...</ElementWithScrollableContent>
        </TouchScrollable>

        // you can also toggle the lock based on some state.
        <ScrollLock isActive={this.state.lockScroll} />
      </div>
    );
  }
}

Props

ScrollLock

PropertyDescription
accountForScrollbars booleanDefault: true -- Whether or not to replace the scrollbar width when active.
isActive booleanDefault: true -- Whether or not the lock is active.
children elementDefault: null -- This element is wrapped internally by the TouchScrollable component.

TouchScrollable

Wrap an element in the TouchScrollable component if you need an area that supports scroll on mobile.

This is necessary because the touchmove event is explicitly cancelled — iOS doesn't observe overflow: hidden; when applied to the <body /> element 😢

PropertyDescription
children elementref => element