好吧。我正在使用模态框弹出窗口来显示动态表的业务详细信息。这张 table 很长。模态框的一切正常,但如果它们滚动到页面底部,它总是会打开页面最顶部的模态框。因此他们必须以这种方式向下滚动很多次。
我目前正在使用此代码将我的模式框居中。
function centerPopup(x){
//request data for centering
var windowWidth = document.documentElement.clientWidth;
var windowHeight = document.documentElement.clientHeight;
var popupHeight = $("#popup" + x).height();
var popupWidth = $("#popup" + x).width();
//centering
$("#popup" + x).css({
"position": "absolute",
"top": windowHeight/2-popupHeight/2,
"left": windowWidth/2-popupWidth/4
});
//only need force for IE6
$('#backgroundPopup').css({
"height": windowHeight
});
}
我不知道这段代码中是否有什么东西影响了它。解决方法是必须向下滚动到它们之前所在的位置,但我找不到太多有关 .position 的文档。
最佳答案
http://www.west-wind.com/weblog/posts/459873.aspx
这个人构建了一个插件,通过添加 .centerInClient 将页面中的任何元素居中。非常光滑。非常节省时间。
关于JQuery 模态框定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1070235/