UNPKG

element-plus

Version:

A Component Library for Vue3.0

32 lines (27 loc) 976 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var isServer = typeof window === 'undefined'; let scrollBarWidth; function scrollbarWidth () { if (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; } exports.default = scrollbarWidth;