shawl.qiu javascript 漂浮广告类(无错兼容多浏览器) Moving v1.0

 shawl.qiu javascript 漂浮广告类(无错兼容多浏览器) Moving v1.0


说明:
写这个其实不难, 不过要考虑兼容问题, 头大了好多.
特别是IE, 许多属性基本上都是摆设....
嗯, 没啥好说的.

PS: 虽然本人不喜欢这些AD相关的东西, 不过有用处的话那就不是讨厌不讨厌的问题了.

目录:
1. 类 Moving 及调用演示

shawl.qiu
2007-05-17
http://blog.csdn.net/btbtd

下载:
http://shawl.qiu.googlepages.com/shawl.qiu_js_class_moving_v1.0.7z

演示:
http://shawl.qiu.googlepages.com/moving.htm

内容:
1. 类 Moving 及调用演示
  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=utf-8" />
  5. <title>shawl.qiu template</title>
  6. <style type="text/css">
  7. /* <![CDATA[ */
  8. .sqMovingAd
  9. {
  10.  border:5px solid #EEEEEE;
  11.  background-color:white;
  12.  padding:5px;
  13. }
  14. /* ]]> */
  15. </style>
  16. <script type="text/javascript">
  17. //<![CDATA[
  18.  /*-----------------------------------------------------------------------------------*/
  19.   * shawl.qiu javascript Moving class v1.0
  20.  /*-----------------------------------------------------------------------------------*/
  21.  //---------------------------------begin class Moving()-------------------------------//
  22.  function Moving()
  23.  { // shawl.qiu code
  24.   //------------------------------------begin public variable
  25.   //---------------begin about
  26.   this.au = {}
  27.   this.au.Subject = "shawl.qiu javascript Moving class";
  28.   this.au.Version = "v1.0";
  29.   this.au.Name = "shawl.qiu";
  30.   this.au.Email = "shawl.qiu@gmail.com";
  31.   this.au.Blog = "http://blog.csdn.net/btbtd";
  32.   this.au.CreatedDate = "2007-5-16";
  33.   this.au.Update = {};
  34.   this.au.Update["1"] = "";
  35.   //---------------end about
  36.   this.Init ={}
  37.   this.Init.Y = 50;
  38.   this.Init.X = 50;
  39.   this.Init.Width = 80;
  40.   this.Init.Height = 80;
  41.   
  42.   this.Delay = 5;
  43.   
  44.   this.Span = {};
  45.   this.Span.XStep = 2;
  46.   this.Span.YStep = 5;
  47.   this.Span.YStepCount = 0;
  48.   
  49.   this.Main = {};
  50.   this.Main.ID = "sqMovingAd";
  51.   this.Main.ClassName = "sqMovingAd";
  52.   this.Main.InnerHtml = "hi there, test ok...";
  53.   //------------------------------------end public variable
  54.   
  55.   //------------------------------------begin private variable
  56.   var Tl = this;
  57.   var pMain = null;
  58.   //------------------------------------end private variable
  59.   
  60.   //------------------------------------begin public method
  61.   this.Go = fGo;
  62.   //------------------------------------end public method
  63.  
  64.   //------------------------------------begin private method
  65.   function fGo()
  66.   { 
  67.    var EleDiv = document.createElement("div");
  68.     
  69.     var Height = 0;
  70.     var Width = 0;
  71.     
  72.     with(EleDiv)
  73.     {
  74.      id = Tl.Main.ID;
  75.      className = Tl.Main.ClassName;
  76.      innerHTML = Tl.Main.InnerHtml;
  77.      style.width = Tl.Init.Width+"px";
  78.      style.height = Tl.Init.Height+"px";
  79.      style.top = Tl.Init.Y+"px";
  80.      style.left = Tl.Init.X+"px";
  81.      if(fCkBrs()==1)
  82.      {
  83.       style.position = "absolute";
  84.      }
  85.      else
  86.      {
  87.       style.position = "fixed";
  88.      }
  89.     } // end with
  90.     
  91.     document.body.appendChild(EleDiv);
  92.     EleDiv = null;
  93.     
  94.     pMain = document.getElementById(Tl.Main.ID);
  95.     
  96.     // for opera
  97.     if(true) //fCkBrs()==2
  98.     {
  99.      var sqMoving =
  100.       setInterval
  101.       (
  102.        function()
  103.        { 
  104.         var iTemp = 0;
  105.         if(fCkBrs()==2)
  106.         {
  107.          iTemp = 18;
  108.         }          
  109.         else if (fCkBrs()==1)
  110.         {
  111.          iTemp = 1;
  112.         }
  113.         else
  114.         {
  115.          iTemp = 0;
  116.         }       
  117.          
  118.         var iTop = parseInt(pMain.style.top);
  119.         var iLeft = parseInt(pMain.style.left);
  120.         var Width = document.body.clientWidth-Tl.Init.Width-iTemp;
  121.         
  122.         // begin top 
  123.         if(fCkBrs()==1)
  124.         {
  125.          var ScrollTop = document.documentElement.scrollTop;
  126.          iTop = ScrollTop;
  127.          
  128.          if((fGetViewPortSize()[1]-Tl.Init.Height)<Tl.Span.YStepCount)
  129.          {
  130.           Tl.Span.YStep = -Tl.Span.YStep;
  131.          }
  132.          
  133.          if(Tl.Span.YStepCount<0)
  134.          {
  135.           Tl.Span.YStep = Math.abs(Tl.Span.YStep);
  136.          }
  137.          
  138.          Tl.Span.YStepCount += Tl.Span.YStep;
  139.          
  140.          pMain.style.top = (iTop+Tl.Span.YStepCount)+"px";
  141.         } 
  142.         else
  143.         {
  144.          var Height = fGetViewPortSize()[1]-Tl.Init.Height;
  145.          if(iTop>Height)
  146.          {
  147.           Tl.Span.YStep = -Tl.Span.YStep;
  148.          }
  149.          
  150.          if(iTop<0)
  151.          {
  152.            Tl.Span.YStep = Math.abs(Tl.Span.YStep);
  153.          }
  154.           pMain.style.top = (iTop+Tl.Span.YStep)+"px";
  155.         } 
  156.         // end top 
  157.         
  158.         if(iLeft>Width)
  159.         { 
  160.          Tl.Span.XStep = -Tl.Span.XStep;
  161.         }
  162.         if(iLeft<0)
  163.         { 
  164.          Tl.Span.XStep = Math.abs(Tl.Span.XStep);
  165.         }
  166.         
  167.         pMain.style.left = (iLeft+Tl.Span.XStep)+"px";
  168.        }
  169.        ,
  170.        Tl.Delay
  171.       ); 
  172.     } // end if
  173.     
  174.   } // end function fGo
  175.   
  176.   function fCkBrs()
  177.   {// shawl.qiu script
  178.    switch (navigator.appName)
  179.    {
  180.     case 'Opera': return 2;
  181.     case 'Netscape': return 3;
  182.     defaultreturn 1;
  183.    }
  184.   } // end function fCkBrs 

  185.   function fGetViewPortSize() 
  186.   {// shawl.qiu script
  187.    var myWidth = 0, myHeight = 0;
  188.    if(typeof(window.innerWidth ) == 'number' ) 
  189.    {//Non-IE
  190.     myWidth = window.innerWidth;
  191.     myHeight = window.innerHeight;
  192.    } 
  193.    else if 
  194.    (
  195.     document.documentElement && 
  196.     ( document.documentElement.clientWidth || document.documentElement.clientHeight ) 
  197.     ) 
  198.    {//IE 6
  199.     myWidth = document.documentElement.clientWidth;
  200.     myHeight = document.documentElement.clientHeight;
  201.    } 
  202.    else ifdocument.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  203.    { //IE 4
  204.     myWidth = document.body.clientWidth;
  205.     myHeight = document.body.clientHeight;
  206.    }
  207.    return [myWidth, myHeight];
  208.   } // end function fGetViewPortSize
  209.   //------------------------------------end private method
  210.  } // shawl.qiu code
  211.  //---------------------------------end class Moving()---------------------------------//
  212.  
  213.  onload =
  214.   function()
  215.   {
  216.    var moving = new Moving();
  217.     moving.Go();
  218.     moving = null;
  219.   }
  220. //]]>
  221. </script>
  222. </head>
  223. <body>
  224. <br />
  225. <br /><br />
  226. <br />
  227. <br />
  228. <br />
  229. <br />
  230. <br />
  231. <br />
  232. <br />
  233. <br />
  234. <br />
  235. <br />
  236. <br />
  237. <br />
  238. <br />
  239. <br />
  240. <br />
  241. <br />
  242. <br />
  243. <br />
  244. <br />
  245. <br />
  246. <br />
  247. <br />
  248. <br />

  249. <br />
  250. <br />
  251. <br />
  252. <br />
  253. <br />
  254. <br />
  255. <br />
  256. <br />
  257. <br />
  258. <br />
  259. <br />
  260. <br />
  261. <br />
  262. <br />
  263. <br />
  264. <br />
  265. <br />
  266. <br />
  267. <br />
  268. <br />
  269. <br />
  270. <br />
  271. <br />
  272. <br />
  273. <br />
  274. <br />
  275. <br />
  276. <br />
  277. <br />
  278. <br />
  279. <br />
  280. <br />
  281. <br />
  282. <br />
  283. <br />
  284. <br />
  285. <br />

  286. </body>
  287. </html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值