how to make colorbox responsive

前端 未结 16 1090
情歌与酒
情歌与酒 2021-01-30 13:35

I am using colorbox in a responsive website.

I have a request : I wish that Colorbox automatically adjusts itself to the size and orientation of the screen / mobile devi

16条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 13:39

    Call this on window resize and/or "orientationchange" Where 960 is the preferred width for my colorbox, and my maxWidth = 95%

    var myWidth = 960, percentageWidth = .95;       
    if ($('#cboxOverlay').is(':visible')) {         
        $.colorbox.resize({ width: ( $(window).width() > ( myWidth+20) )? myWidth : Math.round( $(window).width()*percentageWidth ) });
        $('.cboxPhoto').css( {
            width: $('#cboxLoadedContent').innerWidth(),
            height: 'auto'
        });
        $('#cboxLoadedContent').height( $('.cboxPhoto').height() );
        $.colorbox.resize();
    
    }
    

提交回复
热议问题