# lock-background-scroll

> prevent body or parent scroll element scroll, just for iOS

Latest version **1.0.3** (published 2019-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install lock-background-scroll
pnpm add lock-background-scroll
yarn add lock-background-scroll
bun add lock-background-scroll
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2019-08-22 |
| First published | 2019-08-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | zeyong.tsai |
| Maintainers | zeyong.tsai |
| Keywords | prevent, scroll, lock, body, modal, scroll |

## Links

- npm: https://www.npmjs.com/package/lock-background-scroll
- Repository: https://github.com/zeyongTsai/lock-background-scroll
- Homepage: https://github.com/zeyongTsai/lock-background-scroll#readme
- Issues: https://github.com/zeyongTsai/lock-background-scroll/issues
- npm.io page: https://npm.io/package/lock-background-scroll

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2019-08-22
- 1.0.1 — 2019-08-21
- 1.0.0 — 2019-08-21

## README

# lock-background-scroll
prevent body or parent scroll element scroll, just for iOS

## Why lock-background-scroll ?
On iOS, when a `touchmove` event occurs on an element, the scrollable element in the parent responds to the scroll event. We can prevent this behavior by using `event.preventDefault`, but this will cause the internal scrollable area to not scroll. So this project is intended to solve this problem, it is only used in this case, so it does not apply to the PC side (maybe you want the `mousescroll` event will not cause scrolling), it does not handle whether to lock the body, eliminate the scroll bar, etc.

## Install
```shell
npm i lock-background-scroll
```

## Usage
```javascript
import LockBgScroll from 'lock-background-scroll'
// get the target element
let modal = document.querySelector('.modal')
// init LockBgScroll
let lbs = new LockBgScroll(modal).init()
// destroy it when page or component unload
// lbs.destroy()
```
If there are some scrollable children element inside of `.modal` element, add `data-scroll-container="1"` to them
```html
<div class="modal">
  <div class="modal__head"></div>
  <div class="modal__body" data-scroll-container="1">
    ...
  </div>
</div>
```

## Demo
https://codepen.io/tsai_snick/full/MWgbJGP

---
_Source: https://npm.io/package/lock-background-scroll · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
