function showDialog(){
var $by = $(window),
obj = $('.dialog'),
brsW = $by.width(),
brsH = $by.height(),
sclL = $by.scrollLeft(),
sclT = $by.scrollTop(),
curW = obj.width(),
curH = obj.height();
//计算对话框居中时的左、上边距
var left = sclL + (brsW - curW)/2;
var top = sclT + (brsH - curH)/2;
//设置对话框的位置
obj.css({"left":left,"top":top});
console.log(sclT,sclL)
}
showDialog();
$(window).resize(function(){
showDialog();
})
.dialog{
width: 500px;
height: 500px;
border: 1px solid #ddd;
position: absolute;
}