$(".testButton").click(function(){
$(".testBg").show();
showDiv();
})
})
function showDiv(){
var testContTop=($(window).height()-$(".testCont").height())/2; //计算弹出的框距离页面顶部的距离
var testContWidth=($(window).width()-$(".testCont").width())/2; //计算弹出的框距离页面左边的距离
$(".testCont").css({
"top":testContTop,
"left":testContWidth
});
}
从上面程序可以看出在遮罩层弹出显示以后再执行一个函数动态的设置弹出层的背景大小和距离页面的上间距和左间距,而不是一开始加载JS时就已经设置好弹出层各项参数。










