Skip to content

Commit d9a6ac1

Browse files
committed
Modal: Delete blur background and handle scrollbar
1 parent 3d2bc1f commit d9a6ac1

24 files changed

+221
-390
lines changed

css/pico.classless.css

+14-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.classless.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.classless.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.classless.min.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.css

+14-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.fluid.classless.css

+14-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.fluid.classless.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.fluid.classless.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.fluid.classless.min.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/pico.min.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/css/pico.docs.css

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/css/pico.docs.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/css/pico.docs.min.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/css/pico.docs.min.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/js/modal.js

+37-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
const isOpenClass = 'modal-is-open';
1010
const openingClass = 'modal-is-opening';
1111
const closingClass = 'modal-is-closing';
12+
const animationDuration = 400; // ms
1213
let visibleModal = null;
1314

15+
1416
// Toggle modal
1517
const toggleModal = event => {
1618
event.preventDefault();
@@ -26,11 +28,14 @@ const isModalOpen = modal => {
2628

2729
// Open modal
2830
const openModal = modal => {
31+
if (isScrollbarVisible()) {
32+
document.documentElement.style.setProperty('--scrollbar-width', `${getScrollbarWidth()}px`);
33+
}
2934
document.documentElement.classList.add(isOpenClass, openingClass);
3035
setTimeout(() => {
3136
visibleModal = modal;
3237
document.documentElement.classList.remove(openingClass);
33-
}, 200);
38+
}, animationDuration);
3439
modal.setAttribute('open', true);
3540
}
3641

@@ -40,8 +45,9 @@ const closeModal = modal => {
4045
document.documentElement.classList.add(closingClass);
4146
setTimeout(() => {
4247
document.documentElement.classList.remove(closingClass, isOpenClass);
48+
document.documentElement.style.removeProperty('--scrollbar-width');
4349
modal.removeAttribute('open');
44-
}, 200);
50+
}, animationDuration);
4551
}
4652

4753
// Close with a click outside
@@ -58,4 +64,32 @@ document.addEventListener('keydown', event => {
5864
if (event.key === 'Escape' && visibleModal != null) {
5965
closeModal(visibleModal);
6066
}
61-
});
67+
});
68+
69+
// Get scrollbar width
70+
const getScrollbarWidth = () => {
71+
72+
// Creating invisible container
73+
const outer = document.createElement('div');
74+
outer.style.visibility = 'hidden';
75+
outer.style.overflow = 'scroll'; // forcing scrollbar to appear
76+
outer.style.msOverflowStyle = 'scrollbar'; // needed for WinJS apps
77+
document.body.appendChild(outer);
78+
79+
// Creating inner element and placing it in the container
80+
const inner = document.createElement('div');
81+
outer.appendChild(inner);
82+
83+
// Calculating difference between container's full width and the child width
84+
const scrollbarWidth = (outer.offsetWidth - inner.offsetWidth);
85+
86+
// Removing temporary elements from the DOM
87+
outer.parentNode.removeChild(outer);
88+
89+
return scrollbarWidth;
90+
}
91+
92+
// Is scrollbar visible
93+
const isScrollbarVisible = () => {
94+
return document.body.scrollHeight > screen.height;
95+
}

docs/js/modal.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)