Created
June 21, 2014 00:36
-
-
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
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
//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