有一个jquery插件问题,我通过load()方法获取iframe的宽和高后,我的dialog不居中了为什么?

bianweiall 2013-12-05
现在得到的结果是dialog先居中,然后再通过iframe的宽高改变了dialog大小,这样我的dialog就没法居中了,要怎么办才能居中呢?

var iframeBoxHeight = $("#" + idName).height();
var iframeBoxWidth = $("#" + idName).width();
contentBox = "<div id=\"" + idName + "-contentBox\" class=\"green-ui-dialog-contentBox\"></div>";
var contentBoxObj = $(contentBox);
$("<iframe id=\"" + idName + "-iframeBox\" src=\"" + urlStr + "\"></iframe>").appendTo(contentBoxObj);
$this.append($(contentBoxObj));
$("#" + idName + "-iframeBox").load(function() {
	iframeBoxHeight = $(this).contents().find("p").height() + 30;
	iframeBoxWidth = $(this).contents().find("p").width() + 30;
	$("#" + idName + "-iframeBox").css({
		"height": iframeBoxHeight + "px",
		"width": iframeBoxWidth + "px"
	});
});

$this.css({
	"display": "none",
	"left": ($(window).width() / 2 - iframeBoxWidth / 2) + "px",
	"top": ($(window).height() / 2 - iframeBoxHeight / 2) + "px",
	"z-index": "10000"
});
Global site tag (gtag.js) - Google Analytics