Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I dynamically resize the jQuery Colorbox plugin?

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

like image 744
James Skidmore Avatar asked Jun 29 '09 21:06

James Skidmore


3 Answers

To dynamicly resize colorbox you want to say.

colorbox.resize({width:"300px" , height:"300px"})

If you want to resize a color box that loads an Iframe you would add something like this to the head of your target document.

$(document).ready(function(){
    var x = $('mydiv').width();
    var y = $('mydiv').height();

    parent.$.colorbox.resize({width:x, height:y});

});
like image 166
user573434 Avatar answered Nov 14 '22 18:11

user573434


In Colorbox 1.3, you can now call the resize function:

$('.item').colorbox.resize();
like image 30
James Skidmore Avatar answered Nov 14 '22 19:11

James Skidmore


When you invoke the colorbox, simply add an onComplete function to it, eg

$('.mycolorboxes').colorbox({    
  onComplete : function() { 
       $(this).colorbox.resize(); 
  }    
});

Therefore each time content is loaded within the colorbox, it kicks off its resize function.

like image 22
Jason Avatar answered Nov 14 '22 20:11

Jason