Bootstrap modal body max height 100%

后端 未结 10 1831
梦如初夏
梦如初夏 2020-12-31 06:37

I have a custom sized (80% height width) bootstrap modal body and it scrolls (body content will overflow on some sized screens)

There are 2 problems:

  1. I
10条回答
  •  半阙折子戏
    2020-12-31 07:22

    I caved in and wrote coffeescript to fix this. If anyone's interested, here's the coffeescript:

    fit_modal_body = (modal) ->
      header = $(".modal-header", modal)
      body = $(".modal-body", modal)
    
      modalheight = parseInt(modal.css("height"))
      headerheight = parseInt(header.css("height")) + parseInt(header.css("padding-top")) + parseInt(header.css("padding-bottom"))
      bodypaddings = parseInt(body.css("padding-top")) + parseInt(body.css("padding-bottom"))
    
      height = modalheight - headerheight - bodypaddings - 5 # fudge factor
    
      body.css("max-height", "#{height}px")
    
    # Here you need to bind your event with the appropriate modal, as an example:
    $(window).resize(() -> fit_modal_body($(".modal")))
    

    Or the equivalent javascript as generated per above.

    var fit_modal_body;
    
    fit_modal_body = function(modal) {
      var body, bodypaddings, header, headerheight, height, modalheight;
      header = $(".modal-header", modal);
      body = $(".modal-body", modal);
      modalheight = parseInt(modal.css("height"));
      headerheight = parseInt(header.css("height")) + parseInt(header.css("padding-top")) + parseInt(header.css("padding-bottom"));
      bodypaddings = parseInt(body.css("padding-top")) + parseInt(body.css("padding-bottom"));
      height = modalheight - headerheight - bodypaddings - 5;
      return body.css("max-height", "" + height + "px");
    };
    
    $(window).resize(function() {
      return fit_modal_body($(".modal"));
    });
    

提交回复
热议问题