保誠-保戶業務員媒合平台
Tomas
2024-04-30 f247f8a4ee7edda57d01b184962b3a3ec04316a7
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
import Vue from 'vue';
 
let scrollBarWidth;
 
export default function() {
  if (Vue.prototype.$isServer) return 0;
  if (scrollBarWidth !== undefined) return scrollBarWidth;
 
  const outer = document.createElement('div');
  outer.className = 'el-scrollbar__wrap';
  outer.style.visibility = 'hidden';
  outer.style.width = '100px';
  outer.style.position = 'absolute';
  outer.style.top = '-9999px';
  document.body.appendChild(outer);
 
  const widthNoScroll = outer.offsetWidth;
  outer.style.overflow = 'scroll';
 
  const inner = document.createElement('div');
  inner.style.width = '100%';
  outer.appendChild(inner);
 
  const widthWithScroll = inner.offsetWidth;
  outer.parentNode.removeChild(outer);
  scrollBarWidth = widthNoScroll - widthWithScroll;
 
  return scrollBarWidth;
};