mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-21 02:50:11 +08:00
55348b30b6
* style: use prettier * style: just prettier format, no code changes * style: eslint fix object-shorthand, prefer-const * style: fix no-void * style: no-console
30 lines
779 B
TypeScript
30 lines
779 B
TypeScript
import isServer from './isServer'
|
|
|
|
let scrollBarWidth: number
|
|
|
|
export default function (): number {
|
|
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
|
|
}
|