Skip to content

Commit

Permalink
patch to account for vertical scrollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremysawesome committed Oct 6, 2012
1 parent f9b94fb commit 4a74c20
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions colorbox/jquery.colorbox.js
Expand Up @@ -616,13 +616,32 @@
settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
return settings.h;
}
function getWidthWithScrollbar(){
// we have to "show" the content to calculate the scrollWidth and clientWidth correctly
$loaded.css('visibility', 'hidden').show();

// modify the box width to accomodate for vertical scollbar
var widthDifference = $loaded[0].scrollWidth - $loaded[0].clientWidth;
if(widthDifference > 0)
{
settings.w = getWidth() + widthDifference;
settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
}
$loaded.hide().css('visibility', '');
return settings.w;
}

$loaded.hide()
.appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
.css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
.css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
.prependTo($content);

if(settings.scrolling){
// update width to account for potential vertical scrollbar
$loaded.width(getWidthWithScrollbar());
}

$loadingBay.hide();

// floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width.
Expand Down

0 comments on commit 4a74c20

Please sign in to comment.