UNPKG

1.59 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4Object.defineProperty(exports, "__esModule", {
5 value: true
6});
7exports.default = void 0;
8var _getScrollBarSize = _interopRequireDefault(require("./getScrollBarSize"));
9var _setStyle = _interopRequireDefault(require("./setStyle"));
10function isBodyOverflowing() {
11 return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
12}
13var cacheStyle = {};
14var _default = exports.default = function _default(close) {
15 if (!isBodyOverflowing() && !close) {
16 return;
17 }
18
19 // https://github.com/ant-design/ant-design/issues/19729
20 var scrollingEffectClassName = 'ant-scrolling-effect';
21 var scrollingEffectClassNameReg = new RegExp("".concat(scrollingEffectClassName), 'g');
22 var bodyClassName = document.body.className;
23 if (close) {
24 if (!scrollingEffectClassNameReg.test(bodyClassName)) return;
25 (0, _setStyle.default)(cacheStyle);
26 cacheStyle = {};
27 document.body.className = bodyClassName.replace(scrollingEffectClassNameReg, '').trim();
28 return;
29 }
30 var scrollBarSize = (0, _getScrollBarSize.default)();
31 if (scrollBarSize) {
32 cacheStyle = (0, _setStyle.default)({
33 position: 'relative',
34 width: "calc(100% - ".concat(scrollBarSize, "px)")
35 });
36 if (!scrollingEffectClassNameReg.test(bodyClassName)) {
37 var addClassName = "".concat(bodyClassName, " ").concat(scrollingEffectClassName);
38 document.body.className = addClassName.trim();
39 }
40 }
41};
\No newline at end of file