修改一下自动弹窗htmlhead title自动弹窗特效title style 弹窗样式 modal display none; position fixed; top 50; left 50; transform translate-50 -50; padding 20px; background-col
<html>
<head>
<title>自动弹窗特效</title>
<style>
/* 弹窗样式 */
.modal {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
z-index: 9999;
}
<pre><code>/* 背景暗化样式 */
.overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 9998;
}
</code></pre>
</style>
</head>
<body>
<h1>点击按钮触发自动弹窗</h1>
<!-- 弹窗内容 -->
<div id="modal" class="modal">
<h2>弹窗标题</h2>
<p>这是弹窗的内容。</p>
<button onclick="closeModal()">关闭弹窗</button>
</div>
<!-- 背景暗化层 -->
<div id="overlay" class="overlay"></div>
<script>
var modal = document.getElementById('modal');
var overlay = document.getElementById('overlay');
// 打开弹窗函数
function openModal() {
modal.style.display = 'block';
overlay.style.display = 'block';
}
// 关闭弹窗函数
function closeModal() {
modal.style.display = 'none';
overlay.style.display = 'none';
}
// 自动弹窗
window.onload = function() {
setTimeout(openModal, 3000); // 3秒后自动弹窗
};
</script>
</body>
</html
原文地址: https://www.cveoy.top/t/topic/hZZ9 著作权归作者所有。请勿转载和采集!