`
cenhonggang86830
  • 浏览: 45953 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

将DIV显示在屏幕中间

    博客分类:
  • Java
 
阅读更多
/*设置客户端的高和宽*/
function getClientBounds(){
    var clientWidth;
    var clientHeight;
    
    clientWidth = document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth : document.body.clientWidth;
    clientHeight = document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight :   document.body.clientHeight;
        
    return {width: clientWidth, height: clientHeight};
}
 
/*设置客户端的高和宽*/  
function divcenter(){     
    var divId=document.getElementById('mxh');    
    var rr=new getClientBounds();  
    divId.style.display='block';  
    divId.style.left=(rr.width-divId.clientWidth)/2+document.body.scrollLeft;  
    divId.style.top=(rr.height-divId.clientHeight)/2+document.body.scrollTop;     
}  
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics