1、实现原理:利用display=block以及display=none,加以其他的css样式
2、整体代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
.mask_class{
display: none;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.5);
position: fixed;
top:0;
left: 0;
z-index: 999;
}
.box_class{
display: none;
width: 400px;
height: 300px;
background-color: white;
position: absolute;
left: 40%;
top: 30%;
z-index: 1000;
}
.box_class span{
width: 30px;
height: 30px;
position: absolute;
top:10px;
right: 10px;
cursor: pointer;
}
</style>
<script type="text/javascript">
//var login = document.getElementById("login");
function login_click(){
var mask = document.getElementById("mask");
var box = document.getElementById("box");
mask.style.display = "block";
box.style.display = "block";
}
function login_close(){
var mask = document.getElementById("mask");
var box = document.getElementById("box");
mask.style.display = "none";
box.style.display = "none";
}
</script>
</head>
<body>
<a href="#" id="login" onclick="login_click()">请登录</a>
<div id="mask" class="mask_class"></div>
<div id="box" class="box_class">
<span onclick="login_close()">x</span>
</div>
</body>
</html>