This script provides a cross-browser way of preventing scroll on the body element. A common use case for this is when a modal window is open. Without this script, it’s easy for users to unknowingly scroll the page behind the modal and be disoriented when it’s closed.
Note: Once Safari and iOS Safari support the “touch-action” CSS property (caniuse.com), we can simply toggle a class that adds the following:
/* Create class to allow scrolling on certain elements, like modal windows */
yarn add @threespot/freeze-scroll
;// Disable scrollingscroll;// Enable scrollingscroll;
This is free software and may be redistributed under the terms of the MIT license.
Threespot is an independent digital agency hell-bent on helping those, and only those, who are committed to helping others. Find out more at https://www.threespot.com.