Reliably disable scrolling
Preventing a user from scrolling is a surprisingly challenging thing to do on the web. This library is the most robust solution I know of to disable scrolling.
✓ Mobile and desktop support
✓ Prevents scrolling through keyboard inputs
✓ Never loses the position of the scrollbar
✓ Never causes the scrollbar to appear or disappear unnecessarily
✓ Solid browser support
✓ Zero dependencies
The recommended way to install this package is through npm.
npm install prevent-scroll
Disables scrolling.
Enables scrolling.
import preventScroll from 'prevent-scroll';
// Disable scrolling
preventScroll.on();
// Allow scrolling
preventScroll.off();