Files
modelscope--funasr/web-pages/src/components/ui-scrollbar/scrollbar-width.js
T
2026-07-13 13:25:10 +08:00

30 lines
803 B
JavaScript

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 = 'ui-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
};