对联广告代码效果之三[允许关闭]

现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,本文介绍的这种效果,在1024768分辨率下正常显示,在800600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,而且与前面两个代码不同的是,广告图下方增加了一个图片按纽,允许访客点击关闭广告图片,下面文本框中就是实现效果所需代码:

var delta=0.015;
var collection;
var closeB=false;
function floaters() {
this.items = [];
this.addItem = function(id,x,y,content)
{
document.write('

1<div id="+id+" style="Z-INDEX: 10; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</div>

');

var newItem = {};
newItem.object = document.getElementById(id);
newItem.x = x;
newItem.y = y;

this.items[this.items.length] = newItem;
}
this.play = function()
{
collection = this.items
setInterval('play()',30);
}
}
function play()
{
if(screen.width<=800 || closeB)
{
for(var i=0;i

 1<collection.length;i++) ;="" collection[i].object.style.display="none" dx="(dx" followobj="collection[i].object;" followobj_x="(typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x);" followobj_y="(typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y);" for(var="" i="0;i&lt;collection.length;i++)" if(followobj.offsetleft!="(document.body.scrollLeft+followObj_x))" return;="" var="" {="" }="">0?1:-1)*Math.ceil(Math.abs(dx));   
 2followObj.style.left=followObj.offsetLeft+dx;   
 3} 
 4
 5if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {   
 6var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;   
 7dy=(dy&gt;0?1:-1)*Math.ceil(Math.abs(dy));   
 8followObj.style.top=followObj.offsetTop+dy;   
 9}   
10followObj.style.display = '';   
11}   
12}   
13function closeBanner()   
14{   
15closeB=true;   
16return;   
17} 
18
19var theFloaters = new floaters();   
20//   
21theFloaters.addItem('followDiv1','document.body.clientWidth-100',0,'<a href="http://www.dfeng.net" onclick="closeBanner();" target="_blank"><img border="0" height="554" src="ad/doublead/right.gif" width="100"/></a><br/><br/><img onclick="closeBanner();" src="ad/doublead/close.gif"/>');   
22theFloaters.addItem('followDiv2',0,0,'<a href="http://www.dfeng.net" onclick="closeBanner();" target="_blank"><img border="0" height="400" src="ad/doublead/ad_ad.gif" width="100"/></a><br/><br/><img onclick="closeBanner();" src="ad/doublead/close.gif"/>');   
23theFloaters.play(); 
24
25把上面的代码另存为一个JS文件,然后在想实现此效果的页面用  调用即可,*代表你另存的文件名!注意修改广告图片地址和连接地址!</collection.length;i++)>
Published At
Categories with 网页设计
comments powered by Disqus