JS上下自动漂浮广告,可关闭

[html]  view plain  copy
  1. <%--Keymo,漂浮广告--%>  
  2. <SCRIPT type="text/javascript">  
  3.   
  4.   
  5.     // 这是关闭飘浮广告的宽度,请根据你的广告内容而定  
  6.     var hbcms_ad_width = 100;  
  7.   
  8.   
  9.     // 这是关闭飘浮广告的代码,可以换成图片,点击即可关闭  
  10.     var hbcms_close_str = '<div onClick="closeBanner();" style="color:gray;font-size:9pt;cursor:hand;text-align:center;width:100%;background-color: #efefef;line-height:200%">关闭</div>';  
  11.   
  12.   
  13.     // 设置左边的广告代码,请自己更换图片地址,或换成flash,或换成纯文字  
  14.     // 如果不希望显示左边的广告,可设置为   = '';  
  15.     var hbcms_left_ad = '<embed src="jx_html/images/left.jpg" width="100" height="300" quality="high" wmode="window"></embed>' + hbcms_close_str;  
  16.   
  17.   
  18.   
  19.   
  20.     // 设置右边的广告代码,如果要和左边的广告一致,可设为 = hbcms_left_ad;  
  21.     // 如果不希望显示右边的广告,可设置为 = '';  
  22.     var hbcms_right_ad = '<embed src="jx_html/images/right.jpg" width="100" height="300" quality="high" wmode="window"></embed>' + hbcms_close_str;  
  23.   
  24.   
  25.     var delta = 0.8;  
  26.     var collection;  
  27.     var closeB = false;  
  28.   
  29.   
  30.     function floaters() {  
  31.         this.items = [];  
  32.         this.addItem = function (id, x, y, content) {  
  33.             document.write('<DIV id=' + id + ' style="Z-INDEX: 10; POSITION: absolute;   width:' + hbcms_ad_width + 'px; height:300px;left:' + (typeof (x) == 'string' ? eval(x) : x) + ';top:' + (typeof (y) == 'string' ? eval(y) : y) + '">' + content + '</DIV>');  
  34.   
  35.   
  36.             var newItem = {};  
  37.             newItem.object = document.getElementById(id);  
  38.             newItem.x = x;  
  39.             newItem.y = y;  
  40.   
  41.   
  42.             this.items[this.items.length] = newItem;  
  43.         }  
  44.         this.play = function () {  
  45.             collection = this.items  
  46.             setInterval('play()', 30);  
  47.         }  
  48.     }  
  49.   
  50.   
  51.   
  52.   
  53.     function play() {  
  54.         if (screen.width <= 800 || closeB) {  
  55.             for (var i = 0; i < collection.length; i++) {  
  56.                 collection[i].object.style.display = 'none';  
  57.             }  
  58.             return;  
  59.         }  
  60.         for (var i = 0; i < collection.length; i++) {  
  61.             var followObj = collection[i].object;  
  62.             var followObj_x = (typeof (collection[i].x) == 'string' ? eval(collection[i].x) : collection[i].x);  
  63.             var followObj_y = (typeof (collection[i].y) == 'string' ? eval(collection[i].y) : collection[i].y);  
  64.   
  65.   
  66.             if (followObj.offsetLeft != (document.body.scrollLeft + followObj_x)) {  
  67.                 var dx = (document.body.scrollLeft + followObj_x - followObj.offsetLeft) * delta;  
  68.                 dx = (dx > 0 ? 1 : -1) * Math.ceil(Math.abs(dx));  
  69.                 followObj.style.left = followObj.offsetLeft + dx;  
  70.             }  
  71.   
  72.   
  73.             if (followObj.offsetTop != (document.body.scrollTop + followObj_y)) {  
  74.                 var dy = (document.body.scrollTop + followObj_y - followObj.offsetTop) * delta;  
  75.                 dy = (dy > 0 ? 1 : -1) * Math.ceil(Math.abs(dy));  
  76.                 followObj.style.top = followObj.offsetTop + dy;  
  77.             }  
  78.             followObj.style.display = '';  
  79.         }  
  80.     }  
  81.     function closeBanner() {  
  82.         closeB = true;  
  83.         return;  
  84.     }  
  85.   
  86.   
  87.     var theFloaters = new floaters();  
  88.   
  89.   
  90.     theFloaters.addItem('followDiv1', 'document.body.clientWidth-106', hbcms_ad_width, hbcms_right_ad);  
  91.     //右面广告属性,分别是id,x,y,content  
  92.     theFloaters.addItem('followDiv2', 6, hbcms_ad_width, hbcms_left_ad);  
  93.     //左面广告属性,分别是id,x,y,content  
  94.     theFloaters.play();  
  95.   
  96.   
  97. </script>  
  98. <%--漂浮广告结束--%>  

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值