MCPcopy Create free account
hub / github.com/ElemeFE/element-react / getScrollBarWidth

Function getScrollBarWidth

src/scrollbar/scrollbar-width.js:3–26  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1let scrollBarWidth;
2
3export function getScrollBarWidth() {
4 if (scrollBarWidth !== undefined) return scrollBarWidth;
5
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
14 const widthNoScroll = outer.offsetWidth;
15 outer.style.overflow = 'scroll';
16
17 const inner = document.createElement('div');
18 inner.style.width = '100%';
19 outer.appendChild(inner);
20
21 const widthWithScroll = inner.offsetWidth;
22 scrollBarWidth = widthNoScroll - widthWithScroll;
23 outer.parentNode.removeChild(outer);
24
25 return scrollBarWidth;
26}

Callers 1

renderMethod · 0.90

Calls 1

removeChildMethod · 0.80

Tested by

no test coverage detected