通过一下代码,现在得到的结果是dialog先居中,然后再通过iframe的宽高改变了dialog大小,这样我的dialog就没法居中了,要怎么办才能居中呢?怎样让load()方法执行完后程序再执行下一步?
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"
});
------解决方案--------------------
那应该这么写吧 $(this)
------解决方案--------------------
$this.css({
"display": "none",
"left": ($(window).width() / 2 - iframeBoxWidth / 2) + "px",
"top": ($(window).height() / 2 - iframeBoxHeight / 2) + "px",
"z-index": "10000"
});
扔到load方法里面去