记录cookie的顶部伸缩广告源代码如下:
XML/HTML代码
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>JS特效代码大全(二)能记录cookie的顶部伸缩广告-百洋软件研究实验室</title>
- </head>
-
- <body>
- <div id="ads" style=" width:620px; margin:auto; display:none; margin-top:25px; height:0px;overflow:hidden; ">
- <a href="http://www.po-soft.com" target="_blank"><img src="http://www.po-soft.com/images/image1.jpg" alt="百洋软件研究实验室" width="620" height="195" border="0"/></a> </div>
- <p align="center" style="line-height:24px;">本demo来源于<a href="http://www.po-soft.com/" target="_blank">百洋软件研究实验室</a>博客的<br />
- <a href="http://www.po-soft.com/blog/xuan/145.html">JS特效代码大全(二)能记录cookie的顶部伸缩广告</a>一文。</p>
- </body>
- </html>
- <script type="text/javascript" language="javascript">
- function setCookie(sName,sValue,expireHours) {
- var cookieString = sName + "=" + escape(sValue);
- //;判断是否设置过期时间
- if (expireHours>0) {
- var date = new Date();
- date.setTime(date.getTime + expireHours * 3600 * 1000);
- cookieStringcookieString = cookieString + "; expire=" + date.toGMTString();
- }
- document.cookie = cookieString;
- }
-
-
- function getCookie(sName) {
- var aCookie = document.cookie.split("; ");
- for (var j=0; j < aCookie.length; j++){
- var aCrumb = aCookie[j].split("=");
- if (escape(sName) == aCrumb[0])
- return unescape(aCrumb[1]);
- }
- return null;
- }
- var time = 500;
- var h = 0;
- function addCount()
- {
- if(time>0)
- {
- time--;
- hh = h+15;
- }
- else
- {
- return;
- }
- if(h>195) //高度
- {
- return;
- }
- document.getElementById("ads").style.display = "";
- document.getElementById("ads").style.height = h+"px";
- setTimeout("addCount()",30);
- }
-
- window.onload = function showAds()
- {
- //停留时间自己适当调整
- if(getCookie('load')) //如果cookie有值则判断为已经登陆过,广告隐藏起来
- document.getElementById("ads").style.display="none";
- else //如果cookie没有值则判断为第一次登陆
- {
- setCookie('load',1,24 ); //
-
- addCount();
- setTimeout("noneAds()",7000); //广告显示时间
- }
- }
- </script>
-
- <script type="text/javascript" language="javascript">
- var T = 500;
- var N = 195; //高度
- function noneAds()
- {
- if(T>0)
- {
- T--;
- NN = N-15;
- }
- else
- {
- return;
- }
- if(N<0)
- {
- document.getElementById("ads").style.display = "none";
- return;
- }
-
- document.getElementById("ads").style.height = N+"px";
- setTimeout("noneAds()",30);
- }
- </script>
返回:JS特效代码大全(二)能记录cookie的顶部伸缩广告
另一篇:不记录cookie的顶部伸缩广告源代码
相关文章: JS特效代码大全(一)IE6下PNG图片透明效果的JS特效代码