Created
September 27, 2010 13:12
-
-
Save StevenBlack/598993 to your computer and use it in GitHub Desktop.
Calculate 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
// from http://jdsharp.us/jQuery/minute/calculate-scrollbar-width.php | |
function scrollbarWidth() { | |
var div = $('<div style="width:50px;height:50px;overflow:hidden;position:absolute;top:-200px;left:-200px;"><div style="height:100px;"></div>'); | |
// Append our div, do our calculation and then remove it | |
$('body').append(div); | |
var w1 = $('div', div).innerWidth(); | |
div.css('overflow-y', 'scroll'); | |
var w2 = $('div', div).innerWidth(); | |
$(div).remove(); | |
return (w1 - w2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment