[JavaScript] 两边漂浮的广告源代码(自动跟随滚动) →→→→→进入此内容的聊天室

来自 , 2020-08-16, 写在 JavaScript, 查看 117 次.
URL http://www.code666.cn/view/0141a8ae
  1. //左边
  2. var left_img = '<a href=http://yuncode.net target=_blank><img src=1.gif border=0></a><br><br><a href="http://yuncode.net" target=_blank><img src=2.gif border=0></a>';
  3.  
  4. //上边是两个左边的图片效果,不够可以继续加,代码就是"<br><a href="http://yuncode.net" target=_blank><img src=2.gif border=0></a>"
  5.  
  6. //右边
  7. var right_img = '<a href=http://yuncode.net target=_blank><img src=1.gif border=0></a><br><br><a href="http://yuncode.net" target=_blank><img src=2.gif border=0></a>';
  8. //var right_img='<EMBED src=1.swf quality=high  WIDTH=80 HEIGHT=170 TYPE="application/x-shockwave-flash"></EMBED>';
  9. var delta = 0.05
  10.     var collection;
  11. function floaters()
  12. {
  13.     this.items = [];
  14.     this.addItem = function (id, x, y, content)
  15.     {
  16.         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>');
  17.        
  18.         var newItem = {};
  19.         newItem.object = document.getElementById(id);
  20.         newItem.x = x;
  21.         newItem.y = y;
  22.        
  23.         this.items[this.items.length] = newItem;
  24.     }
  25.     this.play = function ()
  26.     {
  27.         collection = this.items
  28.             setInterval('play()', 10);
  29.     }
  30. }
  31. function play()
  32. {
  33.    
  34.     for (var i = 0; i < collection.length; i++)
  35.     {
  36.         var followObj = collection[i].object;
  37.         var followObj_x = (typeof(collection[i].x) == 'string' ? eval(collection[i].x) : collection[i].x);
  38.         var followObj_y = (typeof(collection[i].y) == 'string' ? eval(collection[i].y) : collection[i].y);
  39.        
  40.         if (followObj.offsetLeft != (document.body.scrollLeft + followObj_x))
  41.         {
  42.             var dx = (document.body.scrollLeft + followObj_x - followObj.offsetLeft) * delta;
  43.             dx = (dx > 0 ? 1 : -1) * Math.ceil(Math.abs(dx));
  44.             followObj.style.left = followObj.offsetLeft + dx;
  45.         }
  46.        
  47.         if (followObj.offsetTop != (document.body.scrollTop + followObj_y))
  48.         {
  49.             var dy = (document.body.scrollTop + followObj_y - followObj.offsetTop) * delta;
  50.             dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy));
  51.             followObj.style.top = followObj.offsetTop + dy;
  52.         }
  53.         followObj.style.display = '';
  54.     }
  55. }
  56.  
  57. var theFloaters = new floaters();
  58. theFloaters.addItem('followDiv1', 'document.body.clientWidth-130', 20, '' + right_img + '');
  59. theFloaters.addItem('followDiv2', 20, 20, '' + left_img + '');
  60. theFloaters.play();

回复 "两边漂浮的广告源代码(自动跟随滚动)"

这儿你可以回复上面这条便签

captcha