antv-l7/node_modules/rc-util/es/switchScrollingEffect.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-11-21 12:04:58 +08:00
import getScrollBarSize from './getScrollBarSize';
export default (function (close) {
var bodyIsOverflowing = document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight) && window.innerWidth > document.body.offsetWidth;
if (!bodyIsOverflowing) {
return;
} // https://github.com/ant-design/ant-design/issues/19729
var scrollingEffectClassName = 'switch-scrolling-effect';
var scrollingEffectClassNameReg = new RegExp("".concat(scrollingEffectClassName), 'g');
var bodyClassName = document.body.className;
if (close) {
document.body.style.position = '';
document.body.style.width = '';
if (scrollingEffectClassNameReg.test(bodyClassName)) {
document.body.className = bodyClassName.replace(scrollingEffectClassNameReg, '').trim();
}
return;
}
var scrollBarSize = getScrollBarSize();
if (scrollBarSize) {
document.body.style.position = 'relative';
document.body.style.width = "calc(100% - ".concat(scrollBarSize, "px)");
if (!scrollingEffectClassNameReg.test(bodyClassName)) {
document.body.className = "".concat(bodyClassName, " ").concat(scrollingEffectClassName);
}
}
});