jqCOOKIES,使广告只显示一次


<link rel="stylesheet" href="css/main.css" />
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<div>
<%-- <button type="button" id="ClickMe">点击显示弹窗遮罩</button>--%>
</div>
</center>
<div id="goodcover"></div>

<div id="code">
<div class="close1"><a href="javascript:void(0)" id="closebt"><img src="picimages/close.gif"></a></div>
<div class="goodtxt" style="font-size:23px">

<div class="code-img"> <a href="gonggao.aspx?id=24"><img id="Img1" src="theme/bg/logo.jpg"></a></div>
<p>亚上蒸蒸洗车</p>
<p>诚邀您的加盟</p>
<p>更多详情请联系我们获取</p>
</div>
<div class="code-img"> <a href="gonggao.aspx?id=24"><img id="ewmsrc" src="picimages/jiameng.png"></a></div>
</div>

<script>


//开始弹出广告代码

 

 

function SetCookie(name, value) {
var Days = 30;
var exp = new Date();
exp.setTime(exp.getTime() + 60 * 2000); //过期时间 2分钟
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

 

 

$(function () {
//alert($(window).height());
//Set the popup window to center
// alert('1');


// var COOKIE_NAME = "mode";


// setTimeout(function () {
// $.cookie(COOKIE_NAME,null, { path: '/'}); //删除cookie

// }, 1000)
//
var COOKIE_NAME = "mode";
if (!$.cookie(COOKIE_NAME)) {
// alert('1');
/*100毫秒显示 时间你自己调*/
setTimeout(function () {
$('#code').center();
$('#goodcover').show();
$('#code').fadeIn();

}, 100)

SetCookie("mode", 1)
// $.cookie(COOKIE_NAME, "mode", { path: '/', expires: 1 });

}

// else {
// $.cookie("mode", null);
// alert('2');
// setTimeout(function () {
// $('#code').center();
// $('#goodcover').show();
// $('#code').fadeIn();

// }, 100)
//
// }

 


$('#ClickMe').click(function () {
// $('#code').center();
// $('#goodcover').show();
// $('#code').fadeIn();
alert('快去申请吧!');
});

 


$('#closebt').click(function () {
$('#code').hide();
$('#goodcover').hide();
});
$('#goodcover').click(function () {
$('#code').hide();
$('#goodcover').hide();
});
/*var val=$(window).height();
var codeheight=$("#code").height();
var topheight=(val-codeheight)/2;
$('#code').css('top',topheight);*/
jQuery.fn.center = function (loaded) {
var obj = this;
body_width = parseInt($(window).width());
body_height = parseInt($(window).height());
block_width = parseInt(obj.width());
block_height = parseInt(obj.height());

left_position = parseInt((body_width / 2) - (block_width / 2) + $(window).scrollLeft());
if (body_width < block_width) {
left_position = 0 + $(window).scrollLeft();
};

top_position = parseInt((body_height / 2) - (block_height / 2) + $(window).scrollTop());
if (body_height < block_height) {
top_position = 0 + $(window).scrollTop();
};

if (!loaded) {

obj.css({
'position': 'absolute'
});
obj.css({
'top': ($(window).height() - $('#code').height()) * 0.5,
'left': left_position
});
$(window).bind('resize', function () {
obj.center(!loaded);
});
$(window).bind('scroll', function () {
obj.center(!loaded);
});

} else {
obj.stop();
obj.css({
'position': 'absolute'
});
obj.animate({
'top': top_position
}, 200, 'linear');
}
}

})
</script>

posted @ 2017-08-28 16:10  sky110  阅读(213)  评论(0编辑  收藏  举报