Prevent scrolling while optionally allowing scrolling on specified elements.
- Prevents scrolling via keyboard
- Maintains scrolling position
- Scrollbar will not disappear
- Can specify elements to still allow scrolling within
- Elements without scrolling disabled do not allow scroll events to overflow out to parent elements
You can install via npm or yarn.
npm install --save prevent-scrolling
yarn add prevent-scrolling
You can import using ES6 imports.
import { PreventScrolling, ReEnableScrolling } from 'prevent-scrolling';
PreventScrolling();
const myScrollableElement = document.querySelector('.MyScrollableElement');
PreventScrolling(myScrollableElement);
const myScrollableElements = [].slice.call(document.querySelectorAll('.MyScrollableElement'));
PreventScrolling(myScrollableElements);
ReEnableScrolling();