switchScrollingEffect.js
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _getScrollBarSize = _interopRequireDefault(require("./getScrollBarSize"));
var _setStyle = _interopRequireDefault(require("./setStyle"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isBodyOverflowing() {
return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
}
var cacheStyle = {};
var _default = function _default(close) {
if (!isBodyOverflowing() && !close) {
return;
} // https://github.com/ant-design/ant-design/issues/19729
var scrollingEffectClassName = 'ant-scrolling-effect';
var scrollingEffectClassNameReg = new RegExp("".concat(scrollingEffectClassName), 'g');
var bodyClassName = document.body.className;
if (close) {
if (!scrollingEffectClassNameReg.test(bodyClassName)) return;
(0, _setStyle.default)(cacheStyle);
cacheStyle = {};
document.body.className = bodyClassName.replace(scrollingEffectClassNameReg, '').trim();
return;
}
var scrollBarSize = (0, _getScrollBarSize.default)();
if (scrollBarSize) {
cacheStyle = (0, _setStyle.default)({
position: 'relative',
width: "calc(100% - ".concat(scrollBarSize, "px)")
});
if (!scrollingEffectClassNameReg.test(bodyClassName)) {
var addClassName = "".concat(bodyClassName, " ").concat(scrollingEffectClassName);
document.body.className = addClassName.trim();
}
}
};
exports.default = _default;