1、修改 JavaScript 代码:
1、修改 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 文件中即可。其他程序建站的朋友可以放到自己相应的 JS 文件里。
2、修改 CSS 样式代码:
/* 弹窗广告css 2018-8-29 */
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 文件中即可。使用其他网站程序的添加到相应的 css 文件中。
3、修改 html 代码:
这段代码是前端显示的 HTML ,将其放到你想要其显示的页面中即可,比如首页文件 index.php 、文章文件 single.php 中即可。
<!-- 弹窗广告 -->
<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>
注意,代码中“./1.png”这里需要修改成你自己的弹窗广告图片地址。这样就可以实现为网站添加弹窗广告的功能了,有网站需要弹窗功能的朋友可以自己试一下。可能这样小小的修改有时候就能为你网站赚钱增加一个新的渠道!
| 1234567891011121314151617181920 | 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 文件中即可。其他程序建站的朋友可以放到自己相应的 JS 文件里。
2、修改 CSS 样式代码:
| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 | /* 弹窗广告css 2018-8-29 */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 文件中即可。使用其他网站程序的添加到相应的 css 文件中。
3、修改 html 代码:
这段代码是前端显示的 HTML ,将其放到你想要其显示的页面中即可,比如首页文件 index.php 、文章文件 single.php 中即可。
| 1234567 | <!– 弹窗广告 –><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> |
注意,代码中“./1.png”这里需要修改成你自己的弹窗广告图片地址。这样就可以实现为网站添加弹窗广告的功能了,有网站需要弹窗功能的朋友可以自己试一下。可能这样小小的修改有时候就能为你网站赚钱增加一个新的渠道!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,默认解压密码为"www.yuankufang.com",如遇到无法解压的请联系管理员!
源库坊 » WordPress 网站添加弹窗广告【纯代码】
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 源库坊

