如何将我的 jQuery 对话框定位到中心? [英] How can I position my jQuery dialog to center?

查看:28
本文介绍了如何将我的 jQuery 对话框定位到中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下代码,但它只将对话框的左上角位置定位到中心,这使得元素向右对齐.如何将对话框居中到计算元素宽度的真实中心,以便中心线将对话框切成 50% 50% 的一半?

I have tried following code, but it only positions dialogs left upper corner position to center, and that makes element to be aligned to right. How can I center dialog to real center which counts elements width, so that center line will cut dialog to 50% 50% halfs?

$('.selector').dialog({ position: 'center' });

http://docs.jquery.com/UI/Dialog#option-position

推荐答案

我很确定你不需要设置位置:

I'm pretty sure you shouldn't need to set a position:

$("#dialog").dialog();

默认应该居中.

我确实看过这篇文章,还检查了 官方 jquery 上的内容-ui 关于定位对话框的站点 :并在其中讨论了两种状态:初始化和初始化之后.

I did have a look at the article, and also checked what it says on the official jquery-ui site about positioning a dialog : and in it were discussed 2 states of: initialise and after initialise.

代码示例 -(取自 jQuery UI 2009-12-03)

使用指定的位置选项初始化对话框.

Initialize a dialog with the position option specified.

$('.selector').dialog({ position: 'top' });

在初始化之后获取或设置位置选项.

Get or set the position option, after init.

//getter
var position = $('.selector').dialog('option', 'position');
//setter
$('.selector').dialog('option', 'position', 'top');

我认为,如果您要删除 position 属性,您会发现它自己居中,否则请尝试第二个 setter 选项,在该选项中您定义了选项"、位置"和中心"的 3 个元素.

I think that if you were to remove the position attribute you would find it centers by itself else try the second setter option where you define 3 elements of "option" "position" and "center".

这篇关于如何将我的 jQuery 对话框定位到中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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