jquery dialog defining maxHeight in percent
Asked Answered
Q

3

10

I have created a small project in which I have to display a modal dialog for which I have used jquery-ui dialog.

I want to define the max height for the dialog in percent. I have tried several things but none of them are working.

Please could someone help me what could be the issue.

See http://jsbin.com/otiley/1/edit

Many thanks

Quotha answered 2/4, 2013 at 8:50 Comment(0)
R
21

Try this link to set height in percent.

$(document).ready(function() {
$('#testColorBox').click(function() {
    var wWidth = $(window).width();
    var dWidth = wWidth * 0.8;
    var wHeight = $(window).height();
    var dHeight = wHeight * 0.8;
    var $link = $(this);
    var $dialog = $('<div></div>')
        .load('test.html')
        .dialog({
            autoOpen: false,
            modal: true,
            title: $link.attr('title'),
            overlay: { opacity: 0.1, background: "black" },
            width: dWidth,
            height: dHeight,
            draggable: false,
                            resizable: false
        });
    $dialog.dialog('open');
    return false;
  });   
});
Reyesreykjavik answered 2/4, 2013 at 8:56 Comment(1)
A short version of this is: $("#selector").dialog({width: $(window).width() * 0.8, height: $(window).height() * 0.8});Diactinic
U
6

jQuery UI only allows you to express the max height in pixels. You will need to perform the calculation to a percentage in your code.

$(document).ready(function(){
  $( "#dialog-modal" ).html($("#temp").html());
  $("div#dialog-modal").dialog({
      height: "auto",
    maxHeight: $("div#dialog-modal").outerHeight() * .2,
      resizable: false,
      width: "70%",
      modal: true,
      title: "Hello"
  });
});
Unconstitutional answered 2/4, 2013 at 8:55 Comment(0)
P
3

You can do so by checking window height or height of some div.

Here's an example : http://jsbin.com/otiley/4/edit

Or :

    $(document).ready(function(){
   var height = $(window).height();
   height = height*0.20;
  $( "#dialog-modal" ).html($("#temp").html());
  $("div#dialog-modal").dialog({
      height: "auto",
      maxHeight: height,
      resizable: false,
      width: "70%",
      modal: true,
      title: "Hello"
  });
});

You can take height of any div and calculate any desired percentage.

Permanence answered 2/4, 2013 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.