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

查看:165
本文介绍了我如何将我的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站点:在其中被讨论了2个状态:初始化和后初始化。

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' });

在init之后获取或设置position选项。

Get or set the position option, after init.

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

我认为如果你要删除position属性,你会发现它自己中心,尝试第二个设置器选项,您可以定义选项位置和中心的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天全站免登陆