我屈服并写了咖啡脚本来解决这个问题。如果有人感兴趣,这里是咖啡脚本:
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")))
或上面生成的等效 javascript。
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"));
});