jquery – 调整大小后如何获得对话框的高度和宽度?

我成功创建了一个带有调整大小启用的对话框但是对于我的项目,我需要在用户调整大小后打开对话框的高度和宽度.

我创建了一个id = opener的按钮和一个id = dialog的div.有人可以帮助我.

使用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:

<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>

解决方法

使用resizeStop事件如下:

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

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

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...