wordpress纯代码增加弹窗广告
作者: 葛屹肃 | 日期: 2023-07-08 | 分类: 知识经验
近日,为了实现某个功能,需要在网站加入弹窗功能。网站是WORDPRESS搭建,因此,涉及到WORDPRESS弹窗代码。
对于WORDPRESS源代码并不熟悉,若要自己研究是不可能的,那只能靠搜索引擎。百度了一下,发现有用的资料并不多,经过一一尝试,发现以下代码可行。
1、JS加入以下代码,只需要放入页面中调用的JS,如:jquery.min.js
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”;
}
2、style.css加入以下代码
// 弹窗广告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; }
}
3、页面上加入以下代码,如:single.php、index.php
<!– 弹窗广告 –>
<div id=”qgg_popup”>
<div>
<span>×</span>
<img src=”./1.png”> // 注:src改为你的图片链接
</div>
</div>
以上代码经小编测试,可实现WORDPRESS网站的弹窗功能,大家可以在此基础上,修改下图片与CSS,实现自己所需要的弹窗广告。
文章链接:https://www.geyisu.com/3166.html