Created
March 11, 2018 23:36
-
-
Save GoodNew5/70797a5ed22aa0446bd2e3ea6a0d7b5c to your computer and use it in GitHub Desktop.
get 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 getScrollBarWidth() { | |
let scrollDiv = document.createElement("div"); | |
scrollDiv.style.overflowY = "scroll"; | |
scrollDiv.style.width = "50px"; | |
scrollDiv.style.height = "50px"; | |
scrollDiv.style.visibility = "hidden"; | |
document.body.appendChild(scrollDiv); | |
let 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