【发布时间】:2011-11-25 07:17:35
【问题描述】:
如何实现,具有自动宽度和高度的 jQuery 模态对话框始终在浏览器中居中。在调整浏览器窗口大小后也是如此。
以下代码不起作用。我认为问题在于自动宽度和高度。
jQuery - 代码
$("<div class='popupDialog'>Loading...</div>").dialog({
autoOpen: true,
closeOnEscape: true,
height: 'auto',
modal: true,
title: 'About Ricky',
width: 'auto'
}).bind('dialogclose', function() {
jdialog.dialog('destroy');
}).load(url, function() {
$(this).dialog("option", "position", ['center', 'center'] );
});
$(window).resize(function() {
$(".ui-dialog-content").dialog("option", "position", ['center', 'center']);
});
谢谢!
【问题讨论】:
-
在
window上绑定resize事件并相应地更新您的top/left定位 -
我想知道他如何将您的评论标记为正确答案? :-)
标签: jquery jquery-ui modal-dialog