Skip to content

Latest commit

 

History

History
97 lines (62 loc) · 1.97 KB

readme.md

File metadata and controls

97 lines (62 loc) · 1.97 KB

Lock body scroll

🌈 Lock/unlock body scrolling when modal is opened

Standard JS Circle CI Codecov npm version npm downloads

Installation

$ yarn add lock-body-scroll

or

$ npm i lock-body-scroll

Usage

ES modules

import createLocker from 'lock-body-scroll'

const locker = createLocker()

// or

const locker = createLocker(options)

locker.lock()

locker.unlock()

CommonJS

const createLocker = require('lock-body-scroll')

const locker = createLocker()

locker.lock()

locker.unlock()

Browser

HTML:

<head>
  <script src="https://cdn.jsdelivr.net/npm/lock-body-scroll" />
</head>

JavaScript:

const locker = window.createLocker()

locker.lock()

locker.unlock()

Options

scrollElement

Default: document.scrollingElement || document.documentElement

The dom element which is for locking scrolling

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT