Last active
March 18, 2019 11:30
-
-
Save olecksamdr/1a7686f5b70c6b1f9d9cb58bab10da7e 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
export const getScrollbarWidth = () => { | |
const scrollDiv = document.createElement('div'); | |
scrollDiv.style.cssText = ` | |
position: absolute; | |
top: -9999px; | |
width: 50px; | |
height: 50px; | |
overflow: scroll | |
`; | |
document.body.appendChild(scrollDiv); | |
const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; | |
document.body.removeChild(scrollDiv); | |
return scrollbarWidth; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment