scrollbar-width.js 786 B

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