对联广告代码效果之一[普通效果]

现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,本文介绍的这种效果,在1024768分辨率下正常显示,在800600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,下面文本框中就是实现效果所需代码:

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

1<div id="+id+" style="Z-INDEX: 0; 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()',10);
}
}
function play()
{
if(screen.width<=800)
{
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}   
13  
14var theFloaters = new floaters();   
15theFloaters.addItem('followDiv1','document.body.clientWidth-100',0,'<br/><a href="广告链接地址" target="_blank"><img border="0" height="400" src="广告图片地址" width="100"/></a>');   
16theFloaters.addItem('followDiv2',0,0,'<br/><a href="广告链接地址" target="_blank"><img border="0" height="400" src="广告图片地址" width="100"/></a>');   
17theFloaters.play(); 
18
19  
20把上面的代码另存为一个JS文件,然后在想实现此效果的页面用  调用即可!注意修改广告图片地址和连接地址!</collection.length;i++)>
Published At
Categories with 网页设计
comments powered by Disqus