Created
December 3, 2021 08:11
-
-
Save faustienf/290d380353a9c1b629976869dfda32f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let scrollWidth: null | number = null; | |
export const getScrollWidth = (): number => { | |
if (scrollWidth !== null) { | |
return scrollWidth; | |
} | |
const el = document.createElement('div'); | |
el.style.position = 'fixed'; | |
el.style.zIndex = '-1'; | |
el.style.visibility = 'hidden'; | |
el.style.overflowY = 'scroll'; | |
el.style.width = '100%'; | |
el.style.height = '1px'; | |
document.body.appendChild(el); | |
scrollWidth = el.offsetWidth - el.clientWidth; | |
document.body.removeChild(el); | |
return scrollWidth; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment