如何在调整大小后得到一个对话框的高度和宽度?

时间:2021-07-19 08:41:16

I created a dialog successfully with resize enable but for my project I need the height and width of the open dialog after it is resized by a user.

我成功地创建了一个带有resize enable的对话框,但是对于我的项目,我需要用户调整打开的对话框的高度和宽度。

I have created a button with id = opener and a div with id = dialog. Can someone please help me if possible.

我创建了一个id = opener按钮,并创建了一个id = dialog的div。如果可能的话,谁能帮我一个忙吗?

Javascript:

Javascript:

// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 1000;
$(function() 
{
    $( "#dialog" ).dialog(
    {
        modal:true,
        autoOpen: false,
        show: "blind",
        hide: "explode",
        buttons: [
        {
            text: "Ok",
            click: function() { $(this).dialog("close"); }
        }] ,
        resizable: true,
        width:'auto',
        height:'auto'
    });

    $( "#opener" ).click(function() 
    {
        $( "#dialog" ).dialog( "open" );
        return false;
    });
});

HTML:

HTML:

<body>
    <div class="demo">
        <div id="dialog" title="Basic dialog">
            <p>My content here. I want to show the height and width of my dialog after it is resized by a user
            </p>    
        </div>
        <button id="opener">Open Dialog</button>
    </div>
</body>

1 个解决方案

#1


7  

Use the resizeStop event as follows:

使用resizeStop事件如下:

$( "#dialog" ).dialog({
    modal:true,
    autoOpen: false,
    show: "blind",
    hide: "explode",
    buttons: [{
             text: "Ok",
             click: function() { $(this).dialog("close"); }
             }] ,
    resizable: true,
    width:'auto',
    height:'auto',
    resizeStop: function(event, ui) {
        alert("Width: " + $(this).outerWidth() + ", height: " + $(this).outerHeight());        
    }
});

The content of the function specified in the resizeStop option is triggered after the dialog has been resized.

在调整对话框的大小后,将触发resizeStop选项中指定的函数的内容。

#1


7  

Use the resizeStop event as follows:

使用resizeStop事件如下:

$( "#dialog" ).dialog({
    modal:true,
    autoOpen: false,
    show: "blind",
    hide: "explode",
    buttons: [{
             text: "Ok",
             click: function() { $(this).dialog("close"); }
             }] ,
    resizable: true,
    width:'auto',
    height:'auto',
    resizeStop: function(event, ui) {
        alert("Width: " + $(this).outerWidth() + ", height: " + $(this).outerHeight());        
    }
});

The content of the function specified in the resizeStop option is triggered after the dialog has been resized.

在调整对话框的大小后,将触发resizeStop选项中指定的函数的内容。