js 左右悬浮对联广告代码示例
程序员文章站
2023-12-14 08:43:28
一段js 左右悬浮广告代码,只要修改广告图片地址与连接地址,相应参数根据页面调整下就可以使用这段左右悬浮广告代码了代码:var delta=0.15 var collection; function...
一段js 左右悬浮广告代码,只要修改广告图片地址与连接地址,相应参数根据页面调整下就可以使用这段左右悬浮广告代码了
代码:
var delta=0.15 var collection; function floaters() { this.items = ; this.additem = function(id,x,y,content) { document.write('<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()',10); } } function play() { for(var i=0;i<collection.length;i++) { var followobj = collection[i].object; var followobj_x = (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x); var followobj_y = (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y); if(followobj.offsetleft!=(document.body.scrollleft+followobj_x)) { var dx=(document.body.scrollleft+followobj_x-followobj.offsetleft)*delta; dx=(dx>0?1:-1)*math.ceil(math.abs(dx)); followobj.style.left=followobj.offsetleft+dx; } if(followobj.offsettop!=(document.body.scrolltop+followobj_y)) { var dy=(document.body.scrolltop+followobj_y-followobj.offsettop)*delta; dy=(dy>0?1:-1)*math.ceil(math.abs(dy)); followobj.style.top=followobj.offsettop+dy; } followobj.style.display = ''; } } var thefloaters = new floaters(); thefloaters.additem('followdiv1','document.body.clientwidth-112',230,'<a href=左链接地址 target=_blank><img src=左图片地址 border=0></a>'); thefloaters.additem('followdiv2',12,230,'<a href=右链接地址 target=_blank><img src=右图片地址 border=0></a>'); thefloaters.play();
另存为*.js文件,在页面中引用:<script src="*.js"></script>调用即可,*代表你另存的文件名!
注意:修改广告图片地址和连接地址!相应的参数可以根据页面自行调整。