效果如下

img

在body标签内插入代码(如果是WordPress,可加一些php函数)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!--弹窗公告-->
<div class="layer"></div>
<div id="globalNotice">
<div id='tc-top'>
<div class="tc-title">使用说明</div>
</div>
<div id='content'>
<div class="content-p">
<p>
解压密码为本站域名<span style="box-shadow: inset 0 -22px 0 #fed32a78;"> ruancang.net </span>;解压失败请更换压缩软件,推荐winrar.
<br>
<br>
避免失联,请关注微信公众号<span style="box-shadow: inset 0 -22px 0 #fed32a78;"> 软仓 </span>;问题反馈也请在公众号内直接提问.
</p>
<img style="width:350px;border:1px solid #e1e1e1;" src="https://img.ruancang.net/win/wx-rc-white.png"/><br><br>
</div>
<br>
<div class="content-a">
<a onClick="closeGlobalNotice();" class="btn btn-default" rel='nofollow'>朕已阅</a>
<a href="https://blog.ruancang.net/post/270.html" target="_blank" onClick="redirectUrlToActive();" class="btn btn-default" rel='nofollow'>更多说明</a>
</div>
</div>
</div>

页脚加入JS代码(访问一次便记录cookie,需要Ctrl + Shift + Delete 清理缓存调试)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!-- 公告弹窗界面 -->
<script>
jQuery.cookie = function(name, value, options) {
if(typeof value != 'undefined') {
options = options || {};
if(value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if(options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if(typeof options.expires == 'number') {
date = new Date();
var totalTime = 24 * 3600;
var hour = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
var pastTime = 3600 * hour + 60 * minutes + seconds;
var leftTime = totalTime - pastTime;
date.setTime(date.getTime() + (options.expires * leftTime * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString();
}
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else {
var cookieValue = null;
if(document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for(var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
if(cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
$(function() {
var COOKIE_NAME = "ruancangNet";
if($.cookie(COOKIE_NAME)) {
$(".layer").hide();
$("#globalNotice").hide();
} else {
var ruancangNetH = $(window).height();
var ruancangNetW = $(window).width();
$(".layer").show();
$("#globalNotice").css({
'top': ruancangNetH / 0 - $("#globalNotice").height() / 0,
'left': ruancangNetW / 0 - $("#globalNotice").width() / 0
});
$("#globalNotice").slideDown(300, function() {
setTimeout("closeGloableAd()", '300000');
});
$.cookie(COOKIE_NAME, "ruancangNet", {
path: '/',
expires: 1
});
}
});
function closeGlobalNotice() {
$('#globalNotice').hide();
$('.layer').hide();
}
function redirectUrlToActive() {
$('#globalNotice').hide();
$('.layer').hide();
}
</script>

head标签内引入CSS代码

1
<link rel="stylesheet" href=".../css/notice.css">

CSS代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// 弹窗公告界面
#globalNotice {
width: 400px;
flex-basis: 100%;
margin: 0 auto;
background: #fff;
border-radius: 10px;
box-shadow: 0 0 30px rgba(0, 0, 0, .3);
-webkit-box-shadow: 0 0 30px rgba(0, 0, 0, .3);
overflow: hidden;
position: fixed;
margin: 0 auto;
z-index: 10001;
display: none;
left: 50%;
top: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}

.layer {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
filter: alpha(opacity=50);
opacity: .5;
background: #000;
z-index: 1000;
display: none
}

#globalNotice #tc-top {
width: 100%;
height: 100px;
background-color: #1a95ff;
background: linear-gradient(to left, #5dadf3 0, #4583ca 100%);
}

#globalNotice .tc-title{
color: #fff;
font-size: 36px;
text-align: center;
line-height: 100px;
font-weight: 500;
}

#globalNotice #profile-img {
width: 80px;
height: 80px;
margin: -80px auto 0;
border: 2px solid #fff;
border-radius: 50%;
box-shadow: 0 0 5px rgba(90, 90, 90, .3)
}

#globalNotice #profile-img img {
width: 100%;
background: #fff;
border-radius: 50%
}

#globalNotice #content {
padding: 35px 22px;
}


#globalNotice #content .content-p p {
font-size: 16px;
font-weight: 400;
line-height: 1.4;
color: #484848;
}

#globalNotice #content .content-a {
display: flex;
justify-content: space-around;
}

#globalNotice #content .content-a a {
color: #ccc;
font-size: 14px;
margin: 0 10px;
transition: color .3s ease-in-out;
-webkit-transition: color .3s ease-in-out
}

#globalNotice #content .content-a a:hover {
color: #007bff
}

#globalNotice #content .content-a .btn {
background: none repeat scroll 0 0 #1ba1e2;
border: 0;
border-radius: 2px;
color: #fff!important;
cursor: pointer;
font-size: 14px;
padding: 6px 10%
}

#globalNotice #content .content-a .btn:hover,
.yanshibtn:hover {
background: none repeat scroll 0 0 #9b59b6;
}