设置DIV显示在屏幕中间

/*设置客户端的高和宽*/ 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; }

你可能感兴趣的:(JavaScript)