how to make colorbox responsive

前端 未结 16 1070
情歌与酒
情歌与酒 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:43

    Before colorbox js lock, insert the following code:

    jQuery.colorbox.settings.maxWidth  = '95%';
    jQuery.colorbox.settings.maxHeight = '95%';
    
    var resizeTimer;
    function resizeColorBox()
      {
          if (resizeTimer) clearTimeout(resizeTimer);
          resizeTimer = setTimeout(function() {
                  if (jQuery('#cboxOverlay').is(':visible')) {
                          jQuery.colorbox.load(true);
                  }
          }, 300);
      }
    jQuery(window).resize(resizeColorBox);
    window.addEventListener("orientationchange", resizeColorBox, false);
    

    Leave left, right, bottom and top with value 'false' and it will do the calculation automatically. It worked for me so I'm going over!

提交回复
热议问题