中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

JavaScript 彈窗

以下是一個簡單的 JavaScript 彈窗代碼實(shí)例。

HTML 代碼:

<!-- 打開彈窗按鈕 --> <button id="myBtn">打開彈窗</button> <!-- 彈窗 --> <div id="myModal" class="modal"> <!-- 彈窗內(nèi)容 --> <div class="modal-content"> <span class="close">&times;</span> <p>彈窗中的文本...</p> </div> </div>

CSS 代碼:

/* 彈窗 (background) */ .modal { display: none; /* 默認(rèn)隱藏 */ position: fixed; /* 固定定位 */ z-index: 1; /* 設(shè)置在頂層 */ left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4); } /* 彈窗內(nèi)容 */ .modal-content { background-color: #fefefe; margin: 15% auto; padding: 20px; border: 1px solid #888; width: 80%; } /* 關(guān)閉按鈕 */ .close { color: #aaa; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; }

JavaScript 代碼:

// 獲取彈窗 var modal = document.getElementById('myModal'); // 打開彈窗的按鈕對象 var btn = document.getElementById("myBtn"); // 獲取 <span> 元素,用于關(guān)閉彈窗 var span = document.querySelector('.close'); // 點(diǎn)擊按鈕打開彈窗 btn.onclick = function() { modal.style.display = "block"; } // 點(diǎn)擊 <span> (x), 關(guān)閉彈窗 span.onclick = function() { modal.style.display = "none"; } // 在用戶點(diǎn)擊其他地方時,關(guān)閉彈窗 window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } }

在線演示


彈窗添加頭部和底部

HTML 代碼:

<!-- 打開彈窗按鈕 --> <button id="myBtn">打開彈窗</button> <!-- 彈窗 --> <div id="myModal" class="modal"> <!-- 彈窗內(nèi)容 --> <div class="modal-content"> <div class="modal-header"> <span class="close">&times;</span> <h2>彈窗頭部</h2> </div> <div class="modal-body"> <p>彈窗文本...</p> <p>彈窗文本...</p> </div> <div class="modal-footer"> <h3>彈窗底部</h3> </div> </div> </div>

CSS 代碼:

/* 彈窗 (background) */ .modal { display: none; /* 默認(rèn)隱藏 */ position: fixed; z-index: 1; padding-top: 100px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4); } /* 彈窗內(nèi)容 */ .modal-content { position: relative; background-color: #fefefe; margin: auto; padding: 0; border: 1px solid #888; width: 80%; box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19); -webkit-animation-name: animatetop; -webkit-animation-duration: 0.4s; animation-name: animatetop; animation-duration: 0.4s } /* 添加動畫 */ @-webkit-keyframes animatetop { from {top:-300px; opacity:0} to {top:0; opacity:1} } @keyframes animatetop { from {top:-300px; opacity:0} to {top:0; opacity:1} } /* 關(guān)閉按鈕 */ .close { color: white; float: right; font-size: 28px; font-weight: bold; } .close:hover, .close:focus { color: #000; text-decoration: none; cursor: pointer; } .modal-header { padding: 2px 16px; background-color: #5cb85c; color: white; } .modal-body {padding: 2px 16px;} .modal-footer { padding: 2px 16px; background-color: #5cb85c; color: white; }

在線演示


在底部顯示的彈窗