首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

jquery 中如何让一个容器div显示在当前屏幕正中央?

2012-02-16 
jquery 中怎么让一个容器div显示在当前屏幕正中央? - Web 开发 / Ajax//request data for centeringvar wi

jquery 中怎么让一个容器div显示在当前屏幕正中央? - Web 开发 / Ajax
//request data for centering
var windowWidth = document.body.clientWidth;
var windowHeight = document.body.clientHeight;
var popupHeight = $("#popupContact").height();
var popupWidth = $("#popupContact").width();
//centering
$("#popupContact").css({
  "position": "absolute",
  "top": windowHeight/2-popupHeight/2,
  "left": windowWidth/2-popupWidth/2
}); 

  通过以上方式,可以达到这一点,不过有个问题,就是如果页面很长,那么这个DIV就不会在显示屏的最中间了,而是显示在顶端的最中间。
  如果要使不管页面有多长,比如点了某个按钮,都会显示在当前显示的最中间?怎么做呢,求解决!

[解决办法]

JScript code
var windowWidth = document.body.scrollWidth;var windowHeight = document.body.scrollHeight;
[解决办法]
设置它的x y 坐标
[解决办法]
css吧
margin-left:auto;
mrigin-right:auto;
[解决办法]
用滚动条加上页面的位置就可以算出中心

[解决办法]
if( document.documentElement.clientHeight < document.body.scrollHeight ){
height = document.body.scrollHeight;
}else{
height = document.documentElement.clientHeight;
}

热点排行