The AJAX content loaded in a Colorbox has some JavaScript included that resizes things within the content. Colorbox determines its sizing based on the sizes before all of the AJAX happens. How can I make the Colorbox resize after the content has been loaded?
Here is a link where someone said that you can call colorbox() again after it's been loaded, but I can't figure out how to do that:
http://groups.google.com/group/colorbox/browse_thread/thread/535d21c69e9006b0
Chris's answer got me halfway there but it caused a massive error in IE7/8 as it will call that function everytime the window resizes and even strangely on some asp.net buttons that cause a postback?!?! even when there isn't an active colorbox.
This seems to solve it:
It checks that #colorbox exists using .length, and then checks that it's not hidden which does the trick as I could see in Firebug that when you close the colorbox it isn't fully removed/destroyed just hidden!
Hope this helps..
I needed to use setTimeout method to made resizing work for me.
I do ajax call to get a picture, wait for 2 sec and set colorbox for this picture.
On complete I resize the colorbox with picture size.
Without timeout it didn't work for me because picture wasn't loaded completly and a got width=0, height=0 as picture's size.
Just put this code on the page that opens in the
iframe
:When you invoke the colorbox, simply add an
onComplete
function to it, egTherefore each time content is loaded within the colorbox, it kicks off its resize function.
So, here's another possible solution that is really easy to implement (though it will work on all colorboxes that you're calling, so depending on your situation it might not be the best). If this works for you, you can just drag and drop the code basically anywhere in your code and it will work automatically. The HEIGHT_PERCENTAGE and WIDTH_PERCENTAGE values are so that you can set how large the window will resize to relative to the overall window size. You could add some other values to create minimum sizes, etc.
Part of this answer is adapted from: https://stackoverflow.com/a/3012772/1963978
resize actually takes a jQuery object and uses that to do the resizing. Instead, you can just have the colorbox reload like this: