Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gilbarbara/disable-scroll
Prevent page scrolling
https://github.com/gilbarbara/disable-scroll
scroll
Last synced: 15 days ago
JSON representation
Prevent page scrolling
- Host: GitHub
- URL: https://github.com/gilbarbara/disable-scroll
- Owner: gilbarbara
- License: mit
- Created: 2015-09-07T23:52:20.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-12-04T04:00:38.000Z (almost 4 years ago)
- Last Synced: 2024-10-14T18:51:26.998Z (27 days ago)
- Topics: scroll
- Language: TypeScript
- Homepage: https://codesandbox.io/s/github/gilbarbara/disable-scroll/tree/master/demo
- Size: 388 KB
- Stars: 141
- Watchers: 4
- Forks: 23
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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)