Last active
November 22, 2017 23:58
-
-
Save askd/b39d893ed6a5fcfaf1b726c0c3059b1d to your computer and use it in GitHub Desktop.
Calculate Scrollbar Width
This file contains 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
function calcScrollbarWidth() { | |
const outerDiv = document.createElement('div'); | |
const innerDiv = document.createElement('div'); | |
outerDiv.style.overflow = 'scroll'; | |
document.body.insertBefore(outerDiv, null); | |
outerDiv.insertBefore(innerDiv, null); | |
window.scrollbarWidth = outerDiv.offsetWidth - innerDiv.offsetWidth; | |
outerDiv.removeChild(innerDiv); | |
document.body.removeChild(outerDiv); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment