You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/_util/getScrollBarSize.js

39 lines
958 B

let cached;
7 years ago
export default function getScrollBarSize(fresh) {
7 years ago
if (fresh || cached === undefined) {
const inner = document.createElement('div');
inner.style.width = '100%';
inner.style.height = '200px';
7 years ago
const outer = document.createElement('div');
const outerStyle = outer.style;
7 years ago
outerStyle.position = 'absolute';
outerStyle.top = 0;
outerStyle.left = 0;
outerStyle.pointerEvents = 'none';
outerStyle.visibility = 'hidden';
outerStyle.width = '200px';
outerStyle.height = '150px';
outerStyle.overflow = 'hidden';
7 years ago
outer.appendChild(inner);
7 years ago
document.body.appendChild(outer);
7 years ago
const widthContained = inner.offsetWidth;
outer.style.overflow = 'scroll';
let widthScroll = inner.offsetWidth;
7 years ago
if (widthContained === widthScroll) {
widthScroll = outer.clientWidth;
7 years ago
}
document.body.removeChild(outer);
7 years ago
cached = widthContained - widthScroll;
7 years ago
}
return cached;
7 years ago
}