经测,此JS对联广告代码支持IE6、7、Firefox、Opera等主流浏览器,且符合W3C标准。
一、准备好JS和图片文件
2、把以下代码保存为 ad.js
JavaScript代码
- var lastScrollY=0;
- function heartBeat(){
- var diffY;
- if (document.documentElement && document.documentElement.scrollTop)
- diffY = document.documentElement.scrollTop;
- else if (document.body)
- diffY = document.body.scrollTop
- else
- {/*Netscape stuff*/}
- percent=.1*(diffY-lastScrollY);
- if(percent>0)percent=Math.ceil(percent);
- else percent=Math.floor(percent);
- document.getElementById("adleft").style.top=parseInt(document.getElementById("adleft").style.top)+percent+"px";
- document.getElementById("adright").style.top=parseInt(document.getElementById("adright").style.top)+percent+"px";
- lastScrollY=lastScrollY+percent;
- }
- function adhide(names){document.getElementById(names).style.display='none';}
- function screencl(names){if(screen.width<=800){adhide(names);}}
- zcode="<div id='adleft' style='left:10px;position: absolute;z-index:1;top:100px;'><div style='width:100px;height:300px;background:#ccc;border:#999 solid 1px;'>左联</div><div align='right' style='background:#fff;font-size:0px;'> <img src='images/close.gif' title='关闭' onclick=adhide('adleft') style='cursor:pointer'></div></div>";
- ycode="<div id='adright' style='right:10px;position: absolute;z-index:1;top:100px;'><div style='width:100px;height:300px;background:#ccc;border:#999 solid 1px;'>右联</div><div align='left' style='background:#fff;font-size:0px;'> <img src='images/close.gif' title='关闭' onclick=adhide('adright') style='cursor:pointer'></div></div>";
- document.write(zcode);
- document.write(ycode);
- screencl('adleft');
- screencl('adright');
- window.setInterval("heartBeat()",1);
二、使用说明
1、在网页中用 <script language="JavaScript" src="ad.js"></script> 调用即可。
2、把代码中的“左联”“右联”换成你自己的内容。
3、以前用 document.body 时,过不了W3C和FF这关,用 document.documentElement 代替OK。
如果只想要一联,在其相应 DIV 的 style='left:10px;position: absolute;z-index:1;top:100px;' 加入一句 display: none; 即可。
文章评论(0)
我要第一个评论!
发表评论



