<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.mask {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.4);
z-index: 99999;
display: none;
}
.mask .dialog_box {
width: 600px;
height: 300px;
background-color: #FFFFFF;
position: absolute;
border-radius: 10px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<button id="showBtn">显示</button>
<div class="mask" id="mask">
<div class="dialog_box">
<div class="title">
<button id="hideBtn">关闭</button>
</div>
</div>
</div>
</body>
<script>
let mask = document.getElementById('mask')
let showBtn = document.getElementById('showBtn')
let hideBtn = document.getElementById('hideBtn')
showBtn.onclick = () => {
mask.style.display = 'block'
}
hideBtn.onclick = () => {
mask.style.display = 'none'
}
</script>
</html>
效果图
网友评论