Skip to content

Instantly share code, notes, and snippets.

@socketz
Created June 21, 2014 00:36
Show Gist options
  • Save socketz/42064c2d891b8a0f9aed to your computer and use it in GitHub Desktop.
Save socketz/42064c2d891b8a0f9aed to your computer and use it in GitHub Desktop.
Get the scrollBar browser width tested on jQuery 1.8.3 IE7/8/9 Compatible
//Use this code to know the browser scrollbar width, for better calculation that you'll need in some cases
//jQuery dependency
function scrollbarWidth() {
var div = $('<div class="divSize1" style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div class="divSize2" style="height:100px;"></div>');
$('body').append(div);
div.css('overflow-y', 'scroll');
res = $('.divSize1').outerWidth() - $('.divSize2').outerWidth();
$(div).remove();
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment