Created
July 31, 2021 21:03
-
-
Save jrc03c/077ed32bb1d30332500e9fa227ed2a85 to your computer and use it in GitHub Desktop.
Get the width of a browser scrollbar
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
// from: https://davidwalsh.name/detect-scrollbar-width | |
function getScrollbarWidth() { | |
const div = document.createElement("div") | |
div.style = ` | |
width: 100px; | |
height: 100px; | |
overflow: scroll; | |
position: absolute; | |
top: -9999px; | |
` | |
document.body.appendChild(div) | |
const out = div.offsetWidth - div.clientWidth | |
document.body.removeChild(div) | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment