Last active
July 3, 2021 13:38
-
-
Save kosciolek/02a31bcfa666652b7e0ada57b6e7651d to your computer and use it in GitHub Desktop.
Measure scrollbar width
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
function getScrollbarWidth() { | |
const outer = document.createElement('div'); | |
outer.style.visibility = 'hidden'; | |
outer.style.overflow = 'scroll'; | |
document.body.appendChild(outer); | |
const inner = document.createElement('div'); | |
outer.appendChild(inner); | |
const scrollbarWidth = (outer.offsetWidth - inner.offsetWidth); | |
outer.parentNode.removeChild(outer); | |
return scrollbarWidth; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment