帮我用html 写一个弹窗特效
<!DOCTYPE html>
<html>
<head>
<title>弹窗特效</title>
<style type="text/css">
#overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: none;
z-index: 999;
}
<pre><code> #popup {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
display: none;
z-index: 9999;
}
.close-btn {
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
}
</style>
</code></pre>
</head>
<body>
<button onclick="openPopup()">打开弹窗</button>
<pre><code><div id="overlay"></div>
<div id="popup">
<div class="close-btn" onclick="closePopup()">x</div>
<h2>弹窗标题</h2>
<p>弹窗内容</p>
</div>
<script type="text/javascript">
function openPopup() {
document.getElementById("overlay").style.display = "block";
document.getElementById("popup").style.display = "block";
}
function closePopup() {
document.getElementById("overlay").style.display = "none";
document.getElementById("popup").style.display = "none";
}
</script>
</code></pre>
</body>
</html>
原文地址: https://www.cveoy.top/t/topic/b4cP 著作权归作者所有。请勿转载和采集!