且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

随屏幕滚动的带缓冲效果的右下角广告

更新时间:2021-12-12 01:32:29

一个随屏幕自动滚动的右下角广告代码,这里请注意几个参数:
id 你要滚动的内容的id
r 放在左边还是右边 默认是右边
t 你要放在页面的那个位置默认是贴着底边 0是贴着顶边
f 1表示固定 不写或者0表示滚动(ie6固定无效)
是不是很实用呢,这个版本经过作者二次修正,兼容性还不错 。

Java代码  随屏幕滚动的带缓冲效果的右下角广告
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gbk" />  
  5. <title>随屏幕滚动的带缓冲效果的右下角广告</title>  
  6. <style>  
  7.     html,body{  
  8.         height:2000px;  
  9.     }  
  10. </style>  
  11. </head>  
  12. <body>  
  13.     <div id="aa" style="width:200px;height:200px;background:#c0c0c0;" >拖动滚动条试试哦~</div>  
  14. </body>  
  15. </html>  
  16. <script>  
  17.     function scroll(p){  
  18.         var d = document,w = window,o = d.getElementById(p.id),ie6 = /msie 6/i.test(navigator.userAgent);  
  19.         if(o){  
  20.             o.style.cssText +=";position:"+(p.f&&!ie6?'fixed':'absolute')+";"+(p.r?'left':"right")+":0;"+(p.t!=undefined?'top:'+p.t+'px':'bottom:0');  
  21.             if(!p.f||ie6){  
  22.                 -function(){  
  23.                     var t = 500,st = d.documentElement.scrollTop||d.body.scrollTop,c;  
  24.                     c = st  - o.offsetTop + (p.t!=undefined?p.t:(w.innerHeight||d.documentElement.clientHeight)-o.offsetHeight);//如果你是html 4.01请改成d.body,这里不处理以减少代码  
  25.                     c!=0&&(o.style.top = o.offsetTop + Math.ceil(Math.abs(c)/10)*(c<0?-1:1) + 'px',t=10);  
  26.                     setTimeout(arguments.callee,t)  
  27.                 }()   
  28.             }  
  29.         }    
  30.     }  
  31.     scroll({  
  32.         id:'aa'  
  33.       
  34.     })  
  35. </script>