Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery dialog defining maxHeight in percent

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

like image 527
Nitin Mukesh Avatar asked Apr 02 '13 08:04

Nitin Mukesh


3 Answers

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;
  });   
});
like image 123
ravisolanki07 Avatar answered Nov 10 '22 02:11

ravisolanki07


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"
  });
});
like image 40
Kevin Bowersox Avatar answered Nov 10 '22 02:11

Kevin Bowersox


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.

like image 3
eric.itzhak Avatar answered Nov 10 '22 03:11

eric.itzhak