jQuery UI 对话框动态高度和宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1874325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 12:18:52  来源:igfitidea点击:

jQuery UI dialog dynamic height and width

jqueryjquery-ui-dialog

提问by Luca Romagnoli

I'm using jQuery UI dialog with an iframe:

我正在使用带有 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;
}

Is it possible to set widthand heightlike window size?

是否可以设置widthheight喜欢窗口大小?

thanks

谢谢

回答by Jan Han?i?

According to the documentationyou can.

根据文档你可以。

(Code added since the link does not take user directly to the correct section):

(添加了代码,因为链接不会将用户直接带到正确的部分):

OPTION - width

选项 - 宽度

Initialize the dialog with the width option specified:
Code Examples:

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

Invoke the close method:

调用close方法:

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

Get or set the width option, after initialization:

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

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

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

回答by RendezAWS

You can get the window width and height by

您可以通过以下方式获取窗口宽度和高度

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

and use the variables in your dialog box.

并使用对话框中的变量。

回答by mat-mcloughlin

Add a

添加一个

height: 140,
width: 140,

in with the rest of your options

其他选项