# disable-scroll

> Prevent page scroll

Latest version **0.6.0** (published 2020-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install disable-scroll
pnpm add disable-scroll
yarn add disable-scroll
bun add disable-scroll
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2020-12-04 |
| First published | 2015-09-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 21.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 141 |
| Author | Gil Barbara |
| Maintainers | gilbarbara |
| Keywords | scroll |

## Links

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

## Recent versions

- 0.6.0 (latest) — 2020-12-04
- 0.5.1 — 2020-01-16
- 0.5.0 — 2019-07-14
- 0.4.1 — 2018-12-08
- 0.4.0 — 2017-12-26
- 0.4.0-2 — 2017-12-26
- 0.4.0-1 — 2017-12-26
- 0.4.0-0 — 2017-12-26
- 0.3.0 — 2016-10-07
- 0.2.6 — 2015-09-12
- 0.2.0 — 2015-09-08
- 0.1.0 — 2015-09-07

## README

disable scroll
===

[![NPM version](https://badge.fury.io/js/disable-scroll.svg)](https://www.npmjs.com/package/disable-scroll) [![build status](https://travis-ci.org/gilbarbara/disable-scroll.svg)](https://travis-ci.org/gilbarbara/disable-scroll) [![Maintainability](https://api.codeclimate.com/v1/badges/6a4bbda8255037dca13f/maintainability)](https://codeclimate.com/github/gilbarbara/disable-scroll/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/6a4bbda8255037dca13f/test_coverage)](https://codeclimate.com/github/gilbarbara/disable-scroll/test_coverage)

**Prevent page scrolling like a boss.**  
Supports `scroll, wheel, touchmove, keydown` events.

[Demo](https://codesandbox.io/s/github/gilbarbara/disable-scroll/tree/master/demo)

## Setup

### npm
```bash
npm install --save disable-scroll
```

and import it

```typescript
import disableScroll from 'disable-scroll';
```

## Usage

```typescript
disableScroll.on(); // prevent scrolling
...
disableScroll.off(); // re-enable scroll
```

> If you need to support legacy browsers you need to include the scrollingelement polyfill.

## API

### .on(element?: Element, options?: Options)
Disable page scroll by adding event listeners and locking the scroll position.

Options defaults to: 

```typescript
{
    authorizedInInputs: [32, 37, 38, 39, 40],
    disableKeys: true,
    disableScroll: true,
    disableWheel: true,
    keyboardKeys: [32, 33, 34, 35, 36, 37, 38, 39, 40],
}
```

### .off()
Re-enable page scrolling and remove the listeners.

## Issues

If you find a bug, please file an issue on [our issue tracker on GitHub](https://github.com/gilbarbara/disable-scroll/issues).

## License

MIT

---

Inspired by [jquery-disablescroll](https://github.com/ultrapasty/jquery-disablescroll)

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