Last active
December 13, 2015 17:18
-
-
Save danbrianwhite/38515b9f1397f04ac310 to your computer and use it in GitHub Desktop.
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
function scrollbarWidth() | |
{ | |
var $inner = jQuery('<div style="width: 100%; height:200px;">test</div>'), | |
$outer = jQuery('<div style="width:200px;height:150px; position: absolute; top: 0; left: 0; visibility: hidden; overflow:hidden;"></div>').append($inner), | |
inner = $inner[0], | |
outer = $outer[0]; | |
jQuery('body').append(outer); | |
var width1 = inner.offsetWidth; | |
$outer.css('overflow', 'scroll'); | |
var width2 = outer.clientWidth; | |
$outer.remove(); | |
return (width1 - width2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment