<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
*{
margin: 0px;
padding: 0px;
}
.yinying{
width: 100%;
height: 700px;
background: black;
opacity: 0.5;
top: 0px;
left: 0px;
position: fixed;
z-index: 0;
}
.tanchu{
width: 300px;
height: 200px;
background: green;
position: fixed;
top: 100px;
left: 100px;
z-index: 100;
}
</style>
</head>
<body>
<input type="button" id="but1" value="按钮">
<div class="yinying" hidden="hidden" ></div>
<div class="tanchu" hidden="hidden"></div>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
<p>hvushgijgilsbjgsjiogrjosrij</p>
</body>
</html>
<script>
var yinying=document.getElementsByClassName("yinying")[0];
var but1=document.getElementById("but1");
var tanchu=document.getElementsByClassName("tanchu")[0];
var c_height=document.documentElement.clientHeight;
var c_width=document.documentElement.clientWidth;
var left=c_width/2-150;
var top_=c_height/2-100;
yinying.style.height=c_height
tanchu.style.top=top_+"px";
tanchu.style.left=left+"px";
but1.onclick=function(){
yinying.removeAttribute("hidden")
tanchu.removeAttribute("hidden" )
}
yinying.onclick=function(){
tanchu.setAttribute("hidden","hidden")
yinying.setAttribute("hidden","hidden")
}
window.onresize=function(){
var c_height=document.documentElement.clientHeight;
var c_width=document.documentElement.clientWidth;
var left=c_width/2-150;
var top_=c_height/2-100;
yinying.style.height=c_height
tanchu.style.top=top_+"px";
tanchu.style.left=left+"px";
}
</script>