hide-show-scroll
Advanced tools
Comparing version 1.1.0 to 1.1.1
10
index.js
let html = document.documentElement | ||
let scrollbarWidth | ||
let defaultOverflowStyle | ||
let hidden | ||
@@ -9,4 +10,9 @@ | ||
} | ||
// store existing overflow style | ||
defaultOverflowStyle = defaultOverflowStyle || getComputedStyle(html).overflow | ||
// calculate scrollbar width if any | ||
scrollbarWidth = window.innerWidth - html.clientWidth | ||
// hide overflow | ||
html.style.overflow = 'hidden' | ||
// add padding to compensate for scrollbar and prevent shifting | ||
scrollbarWidth && (html.style.paddingRight = `${scrollbarWidth}px`) | ||
@@ -17,4 +23,4 @@ hidden = true | ||
let show = function () { | ||
html.style.overflow = 'auto' | ||
scrollbarWidth && (html.style.paddingRight = '0') | ||
html.style.overflow = defaultOverflowStyle | ||
scrollbarWidth && (html.style.paddingRight = 0) | ||
hidden = false | ||
@@ -21,0 +27,0 @@ } |
{ | ||
"name": "hide-show-scroll", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"main": "dist/hide-show-scroll.umd.js", | ||
@@ -5,0 +5,0 @@ "module": "index.js", |
145447
74