Created
January 26, 2011 15:31
-
-
Save mindplay-dk/796851 to your computer and use it in GitHub Desktop.
Small plugin that reports the size of the browser's scrollbars in pixels.
This file contains hidden or 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
/*! | |
* jQuery Scrollbar Width v1.0 | |
* | |
* Copyright 2011, Rasmus Schultz | |
* Licensed under LGPL v3.0 | |
* http://www.gnu.org/licenses/lgpl-3.0.txt | |
*/ | |
(function($){ | |
$.scrollbarWidth = function() { | |
if (!$._scrollbarWidth) { | |
var $body = $('body'); | |
var w = $body.css('overflow', 'hidden').width(); | |
$body.css('overflow','scroll'); | |
w -= $body.width(); | |
if (!w) w=$body.width()-$body[0].clientWidth; // IE in standards mode | |
$body.css('overflow',''); | |
$._scrollbarWidth = w; | |
} | |
return $._scrollbarWidth; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great stuff, seems to work well and so simple. :-)