1 | import Vue from 'vue';
|
2 |
|
3 | let scrollBarWidth;
|
4 |
|
5 | export default function() {
|
6 | if (Vue.prototype.$isServer) return 0;
|
7 | if (scrollBarWidth !== undefined) return scrollBarWidth;
|
8 |
|
9 | const outer = document.createElement('div');
|
10 | outer.className = 'el-scrollbar__wrap';
|
11 | outer.style.visibility = 'hidden';
|
12 | outer.style.width = '100px';
|
13 | outer.style.position = 'absolute';
|
14 | outer.style.top = '-9999px';
|
15 | document.body.appendChild(outer);
|
16 |
|
17 | const widthNoScroll = outer.offsetWidth;
|
18 | outer.style.overflow = 'scroll';
|
19 |
|
20 | const inner = document.createElement('div');
|
21 | inner.style.width = '100%';
|
22 | outer.appendChild(inner);
|
23 |
|
24 | const widthWithScroll = inner.offsetWidth;
|
25 | outer.parentNode.removeChild(outer);
|
26 | scrollBarWidth = widthNoScroll - widthWithScroll;
|
27 |
|
28 | return scrollBarWidth;
|
29 | };
|