我可以将jQuery UI对话框居中到div吗? [英] Can I center a jQuery UI dialog to a div?

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

问题描述

我有一个主要的内容div,我想将对话框居中于该div,而不是页面的中心.有任何想法吗?我知道有一个位置实用程序,但是我不知道如何在对话框位置选项中使用它.

I've got a main content div, and I'd like to centre the dialog to that div, rather than to the page. Any ideas? I know there's a position utility, but I can't work out how to use it with the dialog position options.

推荐答案

您是正确的, .position() 是前往此处的方法,就像这样:

You're correct, .position() is the way to go here, like this:

​$("#dialog").dialog()
            .parent() //remember .dialog() wraps the content in another <div>
            .position({ my: 'center', at: 'center', of: '#parent' });
  //or just .position({ of: '#parent' });

在上面的#parent中,它是父元素选择器您可以在此处尝试.您希望myat属性设置为center,以便它们彼此居中居中,然后of选择器是您希望其居中的父选择器.

​ In the above #parent it the parent element selector, you can give it a try here. You want the my and at properties to be center so they're centered op top of one another, then the of selector is the parent selector you want it centered in.

我指定了所有相关选项用于说明,但是由于centermyat的默认选项,因此您可以像在注释行中一样将 just 指定为of以上.

I specified all relevant options for illustration, but since center is the default for my and at, you can specify just the of like I have in the commented line above.

这篇关于我可以将jQuery UI对话框居中到div吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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