@kangc/v-md-editor
Version:
A markdown editor built on Vue
31 lines (23 loc) • 883 B
JavaScript
// Modified from https://github.com/ElemeFE/element/blob/dev/src/utils/scrollbar-width.js
let scrollBarWidth;
const isServer = typeof window === 'undefined';
export default function () {
if (isServer) return 0;
if (scrollBarWidth !== undefined) return scrollBarWidth;
const outer = document.createElement('div');
outer.className = '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;
}