共计 2710 个字符,预计需要花费 7 分钟才能阅读完成。
本 js 效果是主要利用 jquery 来做的,里面有关于 cookie 的知识,如果不知道怎么设置请看 ”js 设置 cookie 实例“。本着条条大路通罗马的原则,当然,你也可以用其它方法来设置 cookie。
实现原理主要是判断 cookie 的值是否还存在。如果存在就不弹,反之弹出窗口。
下面来看一下 js 端的代码:
$(function(){if(getCookie("qqtan")!="qqtan"){setTimeout(alertqq,3000)
}
})
function alertqq(){SetCookie("qqtan","qqtan",1);
var zj=Math.ceil((document.body.clientWidth/2)-(350/2))
var message=new Array();
message[0]="前端开发交流";
message[1]="前端开发爱好者";
message[2]="web 前端开发技术交流";
message[3]="web 前端开发博客推荐";
message[4]="web 技术交流";
message[5]="web 技术爱好";
message[6]="web 技术开发交流";
message[7]="web 前端开发技术交流";
message[8]="web 前端开发博客推荐";
message[9]="web 前端开发技术交流";
var sj=Math.random().toString().substr(2,1)
if($.browser.msie && $.browser.version == "6.0"){$("#box_t").css("position","absolute")
}
var $a1=$("#box_t");
$("#box_t em").html(message[sj]);
var thegiht=$.browser.msie && $.browser.version == "6.0" ? document.documentElement.scrollTop + 260:260;
$a1.fadeIn("slow");
$a1.animate({
top:thegiht,
left:zj
},600);
fixed("#box_t",thegiht);
setTimeout(zd,3000)
$("#box_t .close").click(function(){if($(this).html()=="关闭"){$("#box_t").fadeOut("slow");
}else{zd();
}
})
}
function fixed($id, $top) {
$top = $top == "" ? 0 : $top;
if ($.browser.msie && $.browser.version == "6.0") {$($id).css( {"position" : "absolute"});
$(window).scroll(function() {if($("#box_t .close").html()=="关闭"){
var $kfh = document.documentElement.scrollTop + document.documentElement.offsetHeight-123;
$($id).css("top", $kfh)
}else{
var $kfh = document.documentElement.scrollTop + $top + "px";
$($id).css("top", $kfh)
}
})
} else {$($id).css( {"position" : "fixed"})
}
}
function zd(){$("#box_t .close").html("关闭")
$("#box_t").css({
"display":"none","top":"","left":"",
"right":"0px","bottom":"0px"})
$("#box_t").fadeIn("slow")
}
function SetCookie(name,value,Days)
{
//var Days=30; // 此 cookie 将被保存 30 天
var exp = new Date(); //new Date("December 31, 9998");
exp.setTime(exp.getTime() + Days*24*60*60*1000);
document.cookie = name+"="+escape(value)+"; expires="+exp.toGMTString()+"; path=/";//path 是 cookie 的访问路径}
function getCookie(name)
{var arr = document.cookie.match(new RegExp("(^|)"+name+"=([^;]*)(;|$)"));
if(arr != null)
return unescape(arr[2]);
else
return null;
}
这里可以细看一下
下面是 html 代码
无标题文档
最小 邀请提示 本信息 3 秒后自动处理!
欢迎你访问本博客!web 前端开发博主真诚邀请你加入。
前端开发交流群:51056097。
验证信息是:
请你牢记本站博客:http://suiyidian.cn
在上可以看一上,里面有 jqurey 库,大家别忘记了。如果要看效果,那就是当你进来我的博客的时个那个效果就是。如果想在看,请先清除浏览器的 cookie 在刷新我的博客就可以了。
正文完