How can I dynamically resize the jQuery Colorbox plugin?

前端 未结 16 1511
情书的邮戳
情书的邮戳 2020-12-13 14:14

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 th

相关标签:
16条回答
  • 2020-12-13 14:27

    As I know, colorbox with iframe: true, cannot be resized. Color with iframe: false can resize height only (using jQuery.fn.colorbox.resize()).

    0 讨论(0)
  • 2020-12-13 14:28

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

    $('.item').colorbox.resize();
    
    0 讨论(0)
  • 2020-12-13 14:29

    Just put this code on the page that opens in the iframe:

    $(document).ready(function() {
        parent.$.fn.colorbox.resize({
            innerWidth: $(document).width(),
            innerHeight: $(document).height()
        });
    });
    
    0 讨论(0)
  • 2020-12-13 14:32

    resize actually takes a jQuery object and uses that to do the resizing. Instead, you can just have the colorbox reload like this:

    $(window).resize(function(){
        $.fn.colorbox.load();
    }); 
    
    0 讨论(0)
  • 2020-12-13 14:37

    This one is working properly brothers.

    jQuery( document ).ready( function(){
    var custom_timeout = ( function() {
        var timers = {};
        return function ( callback, ms, uniqueId ) {
            if ( !uniqueId ) {
                uniqueId = "Don't call this twice without a uniqueId";
            }
            if ( timers[uniqueId] ) {
                clearTimeout ( timers[uniqueId] );
            }
            timers[uniqueId] = setTimeout( callback, ms );
          };
    })(); 
    $(".group1").colorbox({rel:'group1', width:"80%" }); 
    $( window ).resize( function(){
        custom_timeout(function(){
            if( $('#cboxOverlay' ).css( 'visibility' ) ){
                $(".group1").colorbox.resize({ innerWidth:'80%' });
            }
        }, 500 );
    }); 
    });
    
    0 讨论(0)
  • 2020-12-13 14:40

    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});
    
    });
    
    0 讨论(0)
提交回复
热议问题