1 | // A change of the browser zoom change the scrollbar size.
|
2 | // Credit https://github.com/twbs/bootstrap/blob/3ffe3a5d82f6f561b82ff78d82b32a7d14aed558/js/src/modal.js#L512-L519
|
3 | export default function getScrollbarSize() {
|
4 | const scrollDiv = document.createElement('div');
|
5 | scrollDiv.style.width = '99px';
|
6 | scrollDiv.style.height = '99px';
|
7 | scrollDiv.style.position = 'absolute';
|
8 | scrollDiv.style.top = '-9999px';
|
9 | scrollDiv.style.overflow = 'scroll';
|
10 | document.body.appendChild(scrollDiv);
|
11 | const scrollbarSize = scrollDiv.offsetWidth - scrollDiv.clientWidth;
|
12 | document.body.removeChild(scrollDiv);
|
13 | return scrollbarSize;
|
14 | } |
\ | No newline at end of file |