how to make colorbox responsive

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

    Add this into your main js file after load the color box related js and jquery lib files.

    (function ($, window, document, undefined) {
    //Configure colorbox call back to resize with custom dimensions 
      $.colorbox.settings.onLoad = function() {
        colorboxResize();
      }
    
      //Customize colorbox dimensions
      var colorboxResize = function(resize) {
        var width = "90%";
        var height = "90%";
    
    if($(window).width() > 960) { width = "860" }
    if($(window).height() > 700) { height = "630" } 
    
    $.colorbox.settings.height = height;
    $.colorbox.settings.width = width;
    
    //if window is resized while lightbox open
    if(resize) {
      $.colorbox.resize({
        'height': height,
        'width': width
          });
        } 
      }
    
        //In case of window being resized
      $(window).resize(function() {
        colorboxResize(true);
      });
    
    })(jQuery, this, this.document);
    

提交回复
热议问题