3

我刚刚下载了 jQuery 1.8.0,也带有自定义的 CSS,并且正在尝试制作一个非常简单的 jQuery 对话框来工作,但是它不会在当前视口中居中,而是在父元素(主体)中并滚动对话框的视口盒子在中间。

我包含了小部件和位置 js 文件并检查了路径是否正确。这就是我所拥有的:

<script src="js/js/jquery-1.8.0.min.js"></script>
<script src="js/js/jquery-ui-1.8.23.custom.min.js"></script>
<script src="js/js/jquery.ui.position.js"></script>
<script src="js/js/jquery.ui.widget.js"></script>

的HTML:

<div id="dialog-confirm" title="Empty the recycle bin?">
    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>

HTML 完全从 jQuery 网站复制而来。最后调用它:

var dialog_confirm=$( '#dialog-confirm' ).dialog();
dialog_confirm.dialog('open');

这些问题中的所有解决方案都没有为我解决:
Dialog box not position center screen
jQuery center element to viewport using center plugin

有谁知道如何解决这个问题?这是 jQuery 对话框的标准行为吗?对我来说似乎很奇怪,还是我弄错了?

4

2 回答 2

4

我经历了从 jQuery 1.7/jQUI 1.8.17 到 jQuery 1.11/jQUI 1.9.2 的升级。(对话框定位在升级前已经正常工作。)

在我的例子中,原因是一个旧的 doctype 触发了 quirks 模式,这导致 jQuery 返回$(window).height为文档的高度而不是视口。切换到 HTML5 doctype ( <!doctype html>) 解决了这个问题。

于 2014-02-28T19:56:13.490 回答
2

如果可以,请尝试使用较旧的 jquery 版本,例如 1.7.x ......这可能会解决它。这不是常见的行为!

于 2012-09-20T21:45:21.800 回答