jQuery对话框的高度&宽度问题 [英] jquery dialog height & width issue

查看:87
本文介绍了jQuery对话框的高度&宽度问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初,我在页面中心显示具有固定高度和宽度的jquery对话框.现在,我想在对话框中放置一个包含大量html内容的div.现在我想动态增加对话框的高度&宽度根据div高度&具有动画功能的宽度,但我希望该对话框应停留在页面的中心.

initially i am showing jquery dialog with fixed height and width at center of page. now i want to put a div with lots of html content inside the dialog. now i want to dynamically increase dialog height & width according to the div height & width with animate function but i want that dialog should stick at the center of page.

对话框第一次在页面中心打开时,以后如果我更改高度&宽度,然后对话框不在页面中心.因此,请帮我提出一个概念,即在高度&设置时如何强制对话框停留在页面中心动画功能会增加宽度.

when dialog open first time at center of page and later if i change the height & width then dialog is not position at the center of page. so help me with concept that how to force dialog stick at center of page when height & width will be increasing with animate function.

 $(document).ready(function () {

         $("#dialog").dialog({
             autoOpen: false,
             bgiframe: true,
             height: 85,
             width: 330,
             modal: false,
             draggable: true,
             resizable: false,
             position: 'center',
             show: {
                 effect: "fade",
                 duration: 1000
             },
             hide: {
                 effect: "fade",
                 duration: 500
             },
             open: function (type, data) {
                 $(this).parent().appendTo("form");
             }
         });
         });

如果可能的话,请通过示例代码向我展示技巧.谢谢

if possible then please show me the trick with sample code. thanks

推荐答案

好的,如果不考虑元素的大小调整,是否可以正常工作?

OK, would this work, assuming nothing about how the element is resized?

$(#dialog).resize(function(){
    var $host = $("#idOfParent");
    var hostHeight = $host.Height();
    var hostWidth = $host.Width();
    // center dialog on screen
    this.left = (hostWidth - this.width) / 2
    this.top= (hostHeight - this.height) / 2
});

http://api.jquery.com/resize/

这篇关于jQuery对话框的高度&宽度问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆