在蓝色理想论坛里看到了的一段代码,可以实现类似网易首页顶部慢慢展开再慢慢收起的广告效果,非常不错,转过来与大家分享。
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 | <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" < head > < meta http-equiv = "Content-Type" content = "text/html; charset=gb2312" /> < title >类似网易首页慢慢展开再慢慢收起的javascript广告效果--志文工作室</ title > < style > *{margin:0;padding:0;} body {height:2000px;} #menu { width:220px; height:420px; position:absolute; z-index:1000; background:url(http://img.jb51.net/imgby/tengyou300.gif) repeat-x top left; } #menu_h { float:right; } #menu_h img { cursor:pointer; } #menu_c { width:188px; height:398px; border:1px solid #666; background:#ecf6f5; margin:12px 0 0 5px; } #menu_c h2 { text-align:center; } </ style > </ head > < body > < div id = "ads" style = "width:900px;height:300px;background:#369;margin:2 auto;" align = center >大家好 !广告就放这儿了~~~< br />< br />< br /> target = "_blank" >< strong >< font color = red >志文工作室-计算机学习交流博客 欢迎您的访问! </ font ></ strong ></ a ></ p > </ div > < script type = "text/javascript" > var time = 300; var h = 0; function addCount() { if(time>0) { time--; h = h+5; } else { return; } if(h>300) //高度 { return; } document.getElementById("ads").style.display = ""; document.getElementById("ads").style.height = h+"px"; setTimeout("addCount()",30); } window.onload = function showAds() { addCount(); setTimeout("noneAds()",7000); //停留时间自己调了 } var T = 300; var N = 300; //高度 function noneAds() { if(T>0) { T--; N = N-5; } else { return; } if(N< 0 ) { document.getElementById("ads") .style.display = "none" ; return; } document.getElementById("ads") .style.height = N +"px"; setTimeout("noneAds()",30); } </script> </ body > </ html > |
这能管用吗? 只是DIV的背景在慢慢展开和收起,广告中的字明显还是固定的,没有被慢慢展开也没有被慢慢收起,只是最后突然消失了
有点意思啊