Created
October 25, 2011 14:10
-
-
Save itrelease/1312855 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
/* | |
.scrollbar-measure { | |
width: 100px; | |
height: 100px; | |
overflow: scroll; | |
position: absolute; | |
top: -9999px; | |
} | |
*/ | |
// Create the measurement node | |
var scrollDiv = document.createElement("div"); | |
scrollDiv.className = "scrollbar-measure"; | |
document.body.appendChild(scrollDiv); | |
// Get the scrollbar width | |
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; | |
console.warn(scrollbarWidth); // Mac: 15 | |
// Delete the DIV | |
document.body.removeChild(scrollDiv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment