标签:
//获取网页宽高 var sHeight=document.documentElement.scrollHeight; var sWidth=document.documentElement.scrollWidth; //获取可视区域宽高 var wHeight=document.documentElement.clientHeight; var wWidth=document.documentElement.clientWidth; //创建div var oMask=document.createElement("div"); oMask.id="mask"; oMask.style.height=sHeight+"px"; oMask.style.width=sWidth+"px"; document.body.appendChild(oMask); //创建div var oLogin=document.createElement("div"); oLogin.id="login"; oLogin.innerHTML="<div class=‘loginCon‘><div id=‘close‘></div></div>"; document.body.appendChild(oLogin); //获取dom元素的宽高 var dHeight=oLogin.offsetHeight; var dWidth=oLogin.offsetWidth; oLogin.style.left=(wWidth-dWidth)/2+"px"; oLogin.style.top=(wHeight-dHeight)/2+"px";
//删除元素 document.body.removeChild(oMask); document.body.removeChild(oLogin);
标签:
原文地址:http://www.cnblogs.com/sunhe/p/4621923.html