Last active
August 29, 2015 14:08
-
-
Save skhilko/0a2b95c3588bf4abd2f8 to your computer and use it in GitHub Desktop.
Detect scrollbar width with JavaScript. Based on a technique by David Walsh http://davidwalsh.name/detect-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
var scrollWidth = (function() { | |
var scrollDiv = document.createElement("div"); | |
scrollDiv.className = "scrollbar-measure"; | |
document.body.appendChild(scrollDiv); | |
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; | |
document.body.removeChild(scrollDiv); | |
return scrollbarWidth; | |
})(); |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment