CSS——遮罩层
作者:互联网
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
p {
width: 300px;
height: 300px;
background: yellow;
position: absolute;
left: 500px;
top: 300px;
display: none;
z-index: 1000;
}
.mask {
width: 100%;
height: 1200px;
background: gray;
position: fixed;
top: 0;
left: 0;
z-index: 100;
opacity: 0.6;
display: none;
}
</style>
</head>
<body>
<button class="btn">点击显示遮罩</button>
<div class="mask"></div>
<p class="p">内容...........................</p>
</body>
<script type="text/javascript">
btn = document.getElementsByClassName("btn")[0]
p = document.getElementsByClassName("p")[0]
mask = document.getElementsByClassName('mask')[0]
let isShow = true
btn.onclick = function(){
if( isShow ){
p.style.display ='block'
mask.style.display = "block"
}else {
p.style.display ="none"
mask.style.display = "none"
}
isShow = !isShow
}
</script>
</html>
标签:遮罩,style,mask,isShow,none,btn,display,CSS 来源: https://www.cnblogs.com/remix777/p/15713791.html