You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A small "CSS helper" script (~4K gzipped) which relies on **CSS variables** in order to programmatically **prevent the ability to scroll** for any scrollable element avoiding "contents jump".
6
6
7
7
🙅 Without this library:
8
8
9
-

9
+

10
10
11
11
💁 With this library:
12
12
13
-

13
+

14
14
15
15
## TL;TR: a body scroll overview
16
16
@@ -30,7 +30,7 @@ to make things worse that technique just **doesn't work** on **iOS safari**: whe
30
30
This library is downloadable via **npm**, which means you can enter the following command directly in your terminal:
31
31
32
32
```console
33
-
$ npm install @memob0x/body-scroll-lock
33
+
$ npm install scroll-padlock
34
34
```
35
35
36
36
This library is entirely written in [standard ECMAScript](https://tc39.es/), this means that you can safely include **src/padlock.mjs** module in your es6 project without affecting your final bundle size.
There are some edge cases in which iOS doesn't play nice: when the page is scrolled the **system bars** become smaller, at that point when the keyboard tray is triggered they become larger again; that can cause visual artifacts as you can see the following gif.
That's because the element on focus is an input element and iOS forces a scroll to that element (to enhance the accessibility) on an area which would be shortly resized because of the system bars getting bigger. Pretty weird, huh?
All [modern browsers](https://teamtreehouse.com/community/what-is-a-modern-browser) have been tested, but here's a list of dependencies that might be needed in order to support older ones:
205
-
* 💥DOM API "[matches](https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill)" method ([polyfill](https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill))
*[CustomEvent](https://caniuse.com/customevent) ([polyfill](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill)), only if library [events](#events) are being used
208
208
*[CSS variables](https://caniuse.com/css-variables), only for scrollbar gaps compensation (since old browsers support _overflow: hidden;_), still the JS API and events can be used to reach a workaround
209
209
210
210
## Demo
211
211
212
-
Have a look at this [demo](https://memob0x.github.io/body-scroll-lock/demo/) to check if this is what you're looking for. 🤞
212
+
Have a look at this [demo](https://memob0x.github.io/scroll-padlock/demo/) to check if this is what you're looking for. 🤞
0 commit comments