with jquery UI dialog, is there anyway to have a max height and use 'auto' if its smaller

前端 未结 8 2200
抹茶落季
抹茶落季 2021-02-07 00:01

I want a dialog to have a max height setting but, if the content is smaller, then to shrink down to do what height = \'auto\' does. Is this possible in JQuery UI di

相关标签:
8条回答
  • 2021-02-07 00:16

    You can do it like this:

     $('#testing').resizable("enable");
     $('#testing').dialog({ maxHeight: 400 });
    
    
    <div id="testing" class="ui-widget-content">
    <h3 class="ui-widget-header">Resizable</h3>
    </div>
    
    0 讨论(0)
  • 2021-02-07 00:18

    Bug #4820 in jQuery UI Dialog is applicable, and you may be interested in the workarounds.

    0 讨论(0)
  • 2021-02-07 00:19

    I use this:

    $('#dialog').dialog({
        maxHeight: $(window).height(),
        open: function() {
            $(this).dialog('option', 'maxHeight', $(window).height());
       }
    });
    

    Resetting maxHeight in "open" is useful when window has changed size.

    0 讨论(0)
  • 2021-02-07 00:19

    You can wrap the dialog contents in another div that has max-height applied, like this:

    <div id="dialog">
      <div style="max-height: 400px;">
          POPUP CONTENTS GO HERE
      </div>
    </div>
    
    0 讨论(0)
  • 2021-02-07 00:21

    After dialog .open(), and filling with .html():

    $("#div").css('max-height','500px');
    
    0 讨论(0)
  • 2021-02-07 00:25

    You can achieve this by doing the following:

    HTML

    <div id="dialog" title="Dialog Title">
        Dialog content
    </div>
    

    JavaScript

    $('#dialog').dialog({
        resizable: false,
        minHeight: 0,
        create: function() {
            $(this).css("maxHeight", 400);        
        }
    });
    

    Check out test case on jsFiddle.

    0 讨论(0)
提交回复
热议问题