Donations
If you find any of the plugins or content on my site useful and would like to donate, feel free to using this link.
Jonathan Sharp is Owner of Out West Media LLC. located near Omaha, Nebraska, USA. Out West Media provides custom jQuery development, web design and web development services. He and his wife are blessed with a beautiful daughter, two horses and two dogs.
jQuery Minute™ Blog
Out West Media - jQuery Consulting
AutoScroll
jdMenu
jdNewsScroll
xmlDOM - create XML document
If you find any of the plugins or content on my site useful and would like to donate, feel free to using this link.
jQuery Minute is a term I coined in how fast and easy jQuery makes coding. "It only takes a jQuery Minute!"
Recently I needed to calculate the browser's scrollbar width for FF 1.5+, IE6 and IE7 (supported browsers for the app). Google returned a handful of solutions with Fleegix.org: Getting the scrollbar width in pixels as the most relivant. One problem though, it doesn't work in the wonderful cursed IE7 browser. Also it doesn't leverage jQuery (...have I mentioned jQuery before? be SURE to check it out and see if it fits your needs).
This solution differ's from Feegix's solution only in leveraging jQuery and not setting a width to the innerMost div. When the div is set to 100%, IE7 will ignore the space that the scrollbar takes up. Since the div is a block element, it will expand by default and respect the scrollbar width.
So here are the steps and then to the code:
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);
}