oLogin.style.marginTop = "-" + oLogin.clientHeight / 2 + "px";
oLogin.style.marginLeft = "-" + oLogin.clientWidth / 2 + "px";
};var oClose = document.getElementById("close");oClose.onclick = function () {oMask.style.display = "none";}}; </script>
</body>
oLogin.style.marginLeft = "-" + oLogin.clientWidth / 2 + "px";
};var oClose = document.getElementById("close");oClose.onclick = function () {oMask.style.display = "none";}}; </script>
</body>
也可以用display实现。css加上 #mask{display:none}
<div id="login-area"><button id="btnLogin" >登录</button></div>
<div id="mask">
<div id="login">
<div class="loginCon" id="loginCon"></div>
<div id="close"></div>
</div>
</div>
<div id="login-area"><button id="btnLogin" >登录</button></div>
<div id="mask">
<div id="login">
<div class="loginCon" id="loginCon"></div>
<div id="close"></div>
</div>
</div>