做為一個(gè)程序員您應(yīng)該要掌握網(wǎng)站彈出式窗口代碼如何寫(xiě),今天金點(diǎn)子小編就給大家分享。
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>網(wǎng)站彈出式窗口</title>
<style>
body {
font-family: Arial, sans-serif;
}
.overlay {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
}
.modal {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
max-width: 600px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<h2>網(wǎng)站彈出式窗口示例</h2>
<p>點(diǎn)擊按鈕打開(kāi)彈出式窗口:</p>
<button id="openModalBtn">打開(kāi)彈出式窗口</button>
<div id="myModal">
<div>
<span>×</span>
<h3>歡迎來(lái)到我們的網(wǎng)站!</h3>
<p>這是一個(gè)網(wǎng)站彈出式窗口。您可以在這里添加任何您想要的內(nèi)容,例如產(chǎn)品介紹、優(yōu)惠活動(dòng)等。</p>
</div>
</div>
<script>
var modal = document.getElementById("myModal");
var btn = document.getElementById("openModalBtn");
var span = document.getElementsByClassName("close")[0];
btn.onclick = function() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
```