額,想了半天不知道如何開篇~~~,還是直接上代碼吧。

JavaScript 代碼
var popup = document.getElementById('qgg_popup'); var popup_box = document.querySelector('.qgg_popup_box'); var popup_close = document.querySelector('.qgg_popup_close'); // 窗口加載時彈出 window.onload = function() { popup.style.display = "block"; } // 點擊窗體其他位置時關閉 window.onclick = function(event) { if (event.target == popup) { popup.style.display = "none"; } } popup_box.onclick = function() { popup.style.display = "none"; } // 點擊關閉按鈕時關閉 popup_close.onclick = function() { popup.style.display = "none"; }
WordPress建站的小伙伴們將JS代碼丟到主題的主JS文件中去即可。DUX主題用戶直接丟到主題 js 文件夾下的 main.js 文件中即可。
CSS樣式代碼
html, body{ margin:0; height:100%; } #qgg_popup{ position: fixed; top: 0; left: 0; display: none; width: 100%; height: 100%; margin: auto; background: rgba(36, 36, 36, 0.8); } .qgg_popup_box { z-index: 10; position: absolute; top: 0; left: 0; bottom: 0; right: 0; width: 280px; height: 396px; margin: auto; text-align: center; } .qgg_popup_close{ position: relative; width: 36px; height: 36px; background: #fff; color: #999; float: right; font-size: 24px; text-align: center; border-radius: 50%; line-height: 36px; font-weight: bold; } .qgg_popup_close:hover, .qgg_popup_close:focus { color: red; cursor: pointer; } .qgg_popup_img{ position:relative; top: 36px; left: 0px; width:240px; height:360px; border-radius: 15px; } @media (max-width: 640px){ .qgg_popup_close{ display: none; } }
使用 WordPress 搭建網站的小伙伴將代碼丟到主題的 style.css 文件中即可。DUX 主題有點兒特殊,丟到 main.css 文件中即可。
前端HTML顯示代碼
<!-- 彈窗廣告 --> <div id="qgg_popup"> <div class="qgg_popup_box"> <span class="qgg_popup_close">×</span> <img class="qgg_popup_img" src="./1.png"> </div> </div>
這段代碼是前端顯示的 HTML ,將其丟到你想要其顯示的頁面中即可,比如 index.php 、single.php 文件中即可。




















