我尝试了下面的代码,但它只将对话框的左上角位置定位到中心位置,这使得元素要右对齐。如何将对话框居中到计算元素宽度的实际中心,以便中心线将对话框切成50% 50%的一半?
$('.selector').dialog({ position: 'center' });
发布于 2010-09-03 10:11:10
最新的jQuery UI有一个position组件:
$("#myDialog").position({
my: "center",
at: "center",
of: window
});
发布于 2012-06-28 21:14:34
因为对话框需要一个位置,所以需要包括js位置。
<script src="jquery.ui.position.js"></script>
发布于 2015-06-03 23:28:12
open: function () {
var win = $(window);
$(this).parent().css({
position: 'absolute',
left: (win.width() - $(this).parent().outerWidth()) / 2,
top: (win.height() - $(this).parent().outerHeight()) / 2
});
}
https://stackoverflow.com/questions/1839702
复制相似问题