首页 > 语言 > JavaScript > 正文

js 左右悬浮对联广告代码示例

2024-05-06 16:11:55
字体:大 中 小
来源:转载
供稿:网友

这篇文章主要介绍了js 左右悬浮对联广告代码示例,需要的朋友可以参考下

一段js 左右悬浮广告代码,只要修改广告图片地址与连接地址,相应参数根据页面调整下就可以使用这段左右悬浮广告代码了

代码:

  1. var delta=0.15 
  2. var collection; 
  3. function floaters() { 
  4. this.items = ; 
  5. this.addItem = function(id,x,y,content) 
  6. { 
  7. 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>'); 
  8.  
  9. var newItem = {}; 
  10. newItem.object = document.getElementById(id); 
  11. newItem.x = x; 
  12. newItem.y = y; 
  13. this.items[this.items.length] = newItem; 
  14. } 
  15. this.play = function() 
  16. { 
  17. collection = this.items 
  18. setInterval('play()',10); 
  19. } 
  20. } 
  21. function play() 
  22. { 
  23. for(var i=0;i<collection.length;i++) 
  24. { 
  25. var followObj = collection[i].object; 
  26. var followObj_x = (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x); 
  27. var followObj_y = (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y); 
  28. if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) { 
  29. var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta; 
  30. dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx)); 
  31. followObj.style.left=followObj.offsetLeft+dx; 
  32. } 
  33. if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) { 
  34. var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta; 
  35. dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy)); 
  36. followObj.style.top=followObj.offsetTop+dy; 
  37. } 
  38. followObj.style.display = ''; 
  39. } 
  40. }  
  41.  
  42. var theFloaters = new floaters(); 
  43. theFloaters.addItem('followDiv1','document.body.clientWidth-112',230,'<a href=左链接地址 target=_blank><img src=左图片地址 border=0></a>'); 
  44. theFloaters.addItem('followDiv2',12,230,'<a href=右链接地址 target=_blank><img src=右图片地址 border=0></a>'); 
  45. theFloaters.play(); 

另存为*.js文件,在页面中引用:调用即可,*代表你另存的文件名!

注意:修改广告图片地址和连接地址!相应的参数可以根据页面自行调整。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选