function setDivCenter(obj){
//Dialog對象寬高
var objwh = {w:0,h:0};
objwh.h = $(obj).height();
objwh.w = $(obj).width();
//Window寬高
var winwh = {w:0,h:0};
winwh.h = getWindowHeight();
winwh.w = getWindowWidth();
//當前滾動到的位置
var scrollPos = {t:0,l:0};
scrollPos.t = $(document).scrollTop();
scrollPos.l = $(document).scrollLeft();
//Dialog顯示位置
var position = {t:0,l:0};
position.t = scrollPos.t+((winwh.h-objwh.h)/2);
position.l = scrollPos.l+((winwh.w-objwh.w)/2);
position.t = position.t<=0?0:position.t;
position.l = position.l<=0?0:position.l;
//移動Dialog居中
$(obj).css("top",position.t);
$(obj).css("left",position.l);
$(obj).css("height","auto");
//內部函數
//獲取瀏覽器高
function getWindowHeight(){
if($.browser.msie){
return document.compatMode == "CSS1Compat"? document.documentElement.clientHeight :
document.body.clientHeight;
}else{
return self.innerHeight;
}
}
//獲取瀏覽器寬
function getWindowWidth (){
if($.browser.msie){
return document.compatMode == "CSS1Compat"? document.documentElement.clientWidth :
document.body.clientWidth;
}else{
return self.innerWidth;
}
}
}
設置居中
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.