diff options
| author | Terry Truong <terry06890@gmail.com> | 2022-05-27 20:53:17 +1000 |
|---|---|---|
| committer | Terry Truong <terry06890@gmail.com> | 2022-05-27 20:56:38 +1000 |
| commit | a2a9434636ae4d9237d69b6c3bc8f538570129e9 (patch) | |
| tree | 2b4b6ba9f3d3c690ba237d5857f4a362e9d6fd4d /src/lib.ts | |
| parent | 98629c3daeca9aab8f57561012463d4ed8636e43 (diff) | |
Add back code that dynamically gets scrollbar widths
Was deleted due to apparent redundancy. Turns out it was still needed
for overflown-node layout.
Diffstat (limited to 'src/lib.ts')
| -rw-r--r-- | src/lib.ts | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -111,3 +111,21 @@ export function capitalizeWords(str: string){ return str.replace(/\b\w/g, x => x.toUpperCase()); // '\b' matches word boundary, '\w' is like [a-zA-Z0-9_], } +// Dynamically obtains scroll bar width +// From stackoverflow.com/questions/13382516/getting-scroll-bar-width-using-javascript +export function getScrollBarWidth(){ + // Create hidden outer div + let outer = document.createElement('div'); + outer.style.visibility = 'hidden'; + outer.style.overflow = 'scroll'; + document.body.appendChild(outer); + // Create inner div + let inner = document.createElement('div'); + outer.appendChild(inner); + // Get width difference + let scrollBarWidth = outer.offsetWidth - inner.offsetWidth; + // Remove temporary divs + outer.parentNode!.removeChild(outer); + // + return scrollBarWidth; +} |
