console
let modal = document.querySelector('.modal')
modal.style.display = "none"
let i = 1
function showModal() {
if (i % 2 != 0) {
modal.style.display = "block"
} else {
modal.style.display = "none"
}
i++
}
<button onclick="showModal()">modaldialog</button>
<div class="modal">
<p class="bg">
页面内容
</p>
<p class="dialog">
<p class="content">
弹出框
</p>
</p>
</div>
.bg {
height: 666px;
width: 100%;
font-size: 60px;
text-align: center;
}
.dialog {
z-index: 999;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
}
.dialog .content {
min-height: 300px;
width: 600px;
background: #fff;
border-radius: 5px;
border: 1px solid #ebeef5;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.modal {
margin: 10px;
}