<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.content{
height: 1800px;
background: white;
}
.shade
{
position: fixed;
top:0;
left: 0;
right: 0;
bottom: 0;
background-color: red;
opacity: 0.5;
}
.model
{
height: 100px;
width: 100px;
position: absolute;
top: 50%;
left: 50%;
opacity: 0.5;
margin-left: -100px;
margin-top:-100px ;
background-color:black;
}
.hid
{
display: none;
}
</style>
</head>
<body>
<div class="content ">
<button onclick="fun()">show</button>
</div>
<div class="shade hid ">
</div>
<div class="model hid">
<button onclick="fun()">show</button>
</div>
<script>
function fun() {
var ele_shande=document.getElementsByClassName("shade")[0];
var ele_modle=document.getElementsByClassName("model")[0];
ele_shande.classList.remove("hid");//移除里面的hid标签.
ele_modle.classList.remove("hid");
}
</script>
</body>
</html>