JS通过设置cookie来控制弹出层,首次打开页面显示弹出层
2016-03-28 14:25
686 查看
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>JS通过设置cookie来控制弹出层,首次打开页面显示弹出层,刷新页面不再显示;关闭浏览器重新打开、清除缓存cookie显示。</title>
<link rel="stylesheet" href="static/css/global.css"/>
<style>
.infor-layer {
background: url('http://edu.csdn.net/static/images/otherlayer.png?150ac022a67') no-repeat top center;
width: 744px;
height: 407px;
position: fixed;
top: 50%;
left: 50%;
z-index: 9990;
margin-top: -203px;
margin-left: -372px;
display: none;
}
.infor-layer .sub-alltext{ width: 258px;
margin: 98px 0 0 210px;}
.infor-layer .sub-alltext h1 {
font-size: 24px;
color: #fff;
}
.infor-layer .sub-alltext p {
font-size: 16px;
line-height: 2;
margin-top: 10px;
color: #fff;
}
.infor-layer .layer-goto-btn {
background: url('http://edu.csdn.net/static/images/layer_other_btn.png?150ac022a65') no-repeat top center;
width: 225px;
height: 47px;
position: absolute;
bottom: 28px;
left: 50%;
display: inline-block;
margin-left: -163px;
}
.infor-layer .layer-goto-btn:hover {
background: url('http://edu.csdn.net/static/images/layer_other_btn_hover.png?150ac022a66') no-repeat top center;
width: 225px;
height: 47px;
}
.infor-layer .close {
width: 25px;
height: 25px;
border-radius: 25px;
color: #04774a;
position: absolute;
font-size: 26px;
top: 53px;
right: 282px;
display: block;
border: 2px solid #04774a;
text-align: center;
line-height: 20px;
}
.markes {
background: #000;
opacity: 0.6;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=60)";
filter: alpha(opacity=60);
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 999;
display: none;
}
</style>
<script type="text/javascript" src="jq.js"></script>
</head>
<body>
<div class="infor-layer">
<div class="sub-alltext">
<h1>讲师会员卡!</h1>
<p>拥有讲师会员卡,学习实惠又全面学习实惠又全面学习实惠又全面学习实惠又全面</p>
</div>
<a href="http://edu.csdn.net/vipCards" target="_blank" class="layer-goto-btn"></a>
<a href="" id="J_indexNoteClose" class="close">×</a>
</div>
<!--半透膜层-->
<div class="markes"></div>
<script>
$(function(){
var t = 1000;
var cname = "cname5574";
setTimeout(function(){
var v = getCookie(cname);
if(v==undefined){
$(".infor-layer").show();
$(".markes").height($(document.body).height()).show();
document.cookie = cname+"=1";
}
},t);
$("#J_indexNoteClose").on('click',function(event){
document.cookie = cname+"=1";
$(".markes").remove();
$(".infor-layer").remove();
event.stopPropagation();
event.preventDefault();
return false;
});
function getCookie(name){
var cookie = document.cookie;
var a = cookie.split("; ");
for(var j=0,m=a.length;j<m;j++){
var b = a[j].split("=");
if(b[0].toLowerCase()==name){
return b[1];
break;
}
}
}
});
</script>
</body>
</html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>JS通过设置cookie来控制弹出层,首次打开页面显示弹出层,刷新页面不再显示;关闭浏览器重新打开、清除缓存cookie显示。</title>
<link rel="stylesheet" href="static/css/global.css"/>
<style>
.infor-layer {
background: url('http://edu.csdn.net/static/images/otherlayer.png?150ac022a67') no-repeat top center;
width: 744px;
height: 407px;
position: fixed;
top: 50%;
left: 50%;
z-index: 9990;
margin-top: -203px;
margin-left: -372px;
display: none;
}
.infor-layer .sub-alltext{ width: 258px;
margin: 98px 0 0 210px;}
.infor-layer .sub-alltext h1 {
font-size: 24px;
color: #fff;
}
.infor-layer .sub-alltext p {
font-size: 16px;
line-height: 2;
margin-top: 10px;
color: #fff;
}
.infor-layer .layer-goto-btn {
background: url('http://edu.csdn.net/static/images/layer_other_btn.png?150ac022a65') no-repeat top center;
width: 225px;
height: 47px;
position: absolute;
bottom: 28px;
left: 50%;
display: inline-block;
margin-left: -163px;
}
.infor-layer .layer-goto-btn:hover {
background: url('http://edu.csdn.net/static/images/layer_other_btn_hover.png?150ac022a66') no-repeat top center;
width: 225px;
height: 47px;
}
.infor-layer .close {
width: 25px;
height: 25px;
border-radius: 25px;
color: #04774a;
position: absolute;
font-size: 26px;
top: 53px;
right: 282px;
display: block;
border: 2px solid #04774a;
text-align: center;
line-height: 20px;
}
.markes {
background: #000;
opacity: 0.6;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=60)";
filter: alpha(opacity=60);
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 999;
display: none;
}
</style>
<script type="text/javascript" src="jq.js"></script>
</head>
<body>
<div class="infor-layer">
<div class="sub-alltext">
<h1>讲师会员卡!</h1>
<p>拥有讲师会员卡,学习实惠又全面学习实惠又全面学习实惠又全面学习实惠又全面</p>
</div>
<a href="http://edu.csdn.net/vipCards" target="_blank" class="layer-goto-btn"></a>
<a href="" id="J_indexNoteClose" class="close">×</a>
</div>
<!--半透膜层-->
<div class="markes"></div>
<script>
$(function(){
var t = 1000;
var cname = "cname5574";
setTimeout(function(){
var v = getCookie(cname);
if(v==undefined){
$(".infor-layer").show();
$(".markes").height($(document.body).height()).show();
document.cookie = cname+"=1";
}
},t);
$("#J_indexNoteClose").on('click',function(event){
document.cookie = cname+"=1";
$(".markes").remove();
$(".infor-layer").remove();
event.stopPropagation();
event.preventDefault();
return false;
});
function getCookie(name){
var cookie = document.cookie;
var a = cookie.split("; ");
for(var j=0,m=a.length;j<m;j++){
var b = a[j].split("=");
if(b[0].toLowerCase()==name){
return b[1];
break;
}
}
}
});
</script>
</body>
</html>
相关文章推荐
- 选项卡的JavaScript实现
- javascript常用的正则表达式
- [BZOJ1029][JSOI2007]建筑抢修
- JavaScript语言精粹——函数
- JSP公用COMMON文件
- 解决js 出现乱码问题
- Extjs4 动态获取下拉框
- js中的arguments对象的使用
- extjs入门
- Extjs4.0版控件属性配置详细讲解。
- jsp中的锚点效果
- js搞定两个网页之间值的传递
- 使用Volley提交Json数据post
- 小试牛刀——JS闭包
- webvr技术之three.js
- JSP 自定义标签tld --迭代器标签
- JavaScript 回调函数抽离调用简记
- a 标签中调用js的几种方法
- js的Promise学习笔记(1)
- JavaScript 原型系统的变迁,以及 ES6 class