2009-12-09 41 views
2

我使用jQuery UI对话框,其中一个iframe:jQuery UI的对话框动态的高度和宽度

function showDialog(url, title, refresh){   
    var horizontalPadding = 30; 
    var verticalPadding = 30; 
    var width = 650; height = 800; 
    $('<iframe id="modalIframeId" allowtransparency="true" style="background-color:#c0c0c0;" frameborder="0" class="ModalIFrame" src="' + url + '" />') 
     .dialog({ 
      title: title,     
      width: width, 
      height: height, 
      modal: true, 
      resizable: true, 
      autoResize: true, 
      close: function(ev, ui) { 
       if(refresh) 
        location.reload(); 
       else 
        $(this).close(); 
      }, 
      overlay: { 
       opacity: 0.7, 
       background: "black" 
      } 
     }) 
     .width(width - horizontalPadding) 
     .height(height - verticalPadding); 
    return false; 
} 

是否有可能设置widthheight像窗口的大小?

感谢

回答

4

按照documentation即可。

(代码添加,因为链路不采取用户直接到正确的部分):

OPTION - 宽度

与指定的宽度选项初始化对话框:
代码示例:

调用关闭方法:

$(".selector").dialog("close"); 

在初始化后获取或设置宽度选项离子:

//Getter 
var width = $(".selector").dialog("option", "width"); 

//Setter 
$(".selector").dialog("option", "width", 500); 
+0

拯救了我的生命,谢谢。 – Flyout

-1

中添加

height: 140, 
width: 140, 

与您的其余选项

+0

他已经有那里了...... –

0

你可以通过

var windowWidth = $(window).width(); 
var windowHeight = $(window).height(); 

的窗口的宽度和高度,并使用变量你的对话框。