Skip to content

Instantly share code, notes, and snippets.

@danbrianwhite
Last active December 13, 2015 17:18
Show Gist options
  • Save danbrianwhite/38515b9f1397f04ac310 to your computer and use it in GitHub Desktop.
Save danbrianwhite/38515b9f1397f04ac310 to your computer and use it in GitHub Desktop.
scrollbarWidth
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