站长视角
用户至上

纯代码为网站添加弹窗广告

优质广告位招租,欢迎联系站长

额,想了半天不知道如何开篇~~~,还是直接上代码吧。

纯代码为网站添加弹窗广告

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">&times;</span>
        <img class="qgg_popup_img" src="./1.png">
    </div>
</div>

这段代码是前端显示的 HTML ,将其丢到你想要其显示的页面中即可,比如 index.php 、single.php 文件中即可。

赞(8)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权, 转载请注明出处。
文章名称:《纯代码为网站添加弹窗广告》
文章链接:https://cnidc.co/4882.html
【声明】:国外主机测评仅分享信息,不参与任何交易,也非中介,所有内容仅代表个人观点,均不作直接、间接、法定、约定的保证,读者购买风险自担。一旦您访问国外主机测评,即表示您已经知晓并接受了此声明通告。
【关于安全】:任何 IDC商家都有倒闭和跑路的可能,备份永远是最佳选择,服务器也是机器,不勤备份是对自己极不负责的表现,请保持良好的备份习惯。
香港110M(含10M CN2)大带宽独服限量促销,香港E3-8G-1T硬盘-3IP,月付仅799!

登录

找回密码

注册