aboutsummaryrefslogtreecommitdiff
path: root/src/lib.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.ts')
-rw-r--r--src/lib.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib.ts b/src/lib.ts
index 69fac57..c13992c 100644
--- a/src/lib.ts
+++ b/src/lib.ts
@@ -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;
+}