Created
November 27, 2013 13:15
-
-
Save smashercosmo/7675442 to your computer and use it in GitHub Desktop.
Snippet to determine 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
/** | |
* Simple function to determine scrollbar width. | |
* Extracted from JqueryUI source and changed to get rid | |
* of jQuery dependency. | |
*/ | |
function getScrollBarWidth() { | |
var w1, w2, | |
div = document.createElement('div'), | |
inner = document.createElement('div'); | |
div.style = { position: 'absolute', width: '50px', height: '50px', overflow: 'hidden' }; | |
inner.style = { height: '100px' }; | |
div.appendChild(inner); | |
document.body.append(div); | |
w1 = inner.offsetWidth; | |
div.style.overflow = 'scroll'; | |
w2 = inner.offsetWidth; | |
if ( w1 === w2 ) w2 = div.clientWidth; | |
div.parentNode.removeChild(div); | |
return w1 - w2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment