scroll-lock-body-2
Version:
scroll lock the body and remember the position
50 lines (45 loc) • 1.69 kB
JavaScript
/*!
* scroll-lock-body-2 v0.0.12
* (c) kunukn
* Released under the MIT License.
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var attribute = 'data-scroll-lock-is-active';
var noPadding = 'scrollLockNoPadding';
var enableScrollLock = function () {
if (document.body.dataset[noPadding] == null) {
var scrollbarWidth = getScrollbarWidth();
if (scrollbarWidth) {
document.body.style.paddingRight = getScrollbarWidth() + 'px';
}
}
document.body.style.overflow = 'hidden';
document.body.setAttribute(attribute, '');
};
var disableScrollLock = function () {
if (document.body.dataset[noPadding] == null) {
document.body.style.paddingRight = '';
}
document.body.style.overflow = '';
document.body.removeAttribute(attribute);
};
var isScrollLockEnabled = function () {
return document.body.getAttribute(attribute) != null;
};
/**
* --------------------------------------------------------------------------
* Bootstrap (v5.0.0): util/scrollBar.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
var getScrollbarWidth = function () {
// https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes
var documentWidth = document.documentElement.clientWidth;
return Math.abs(window.innerWidth - documentWidth);
};
exports.disableScrollLock = disableScrollLock;
exports.enableScrollLock = enableScrollLock;
exports.getScrollbarWidth = getScrollbarWidth;
exports.isScrollLockEnabled = isScrollLockEnabled;
//# sourceMappingURL=index.js.map