Javascript应用--浮动的广告图片

Code:
  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>浮动广告</title>    
  6.   
  7.   
  8. <script type="text/javascript">    
  9.   
  10. var x = 1,y = 1,movex = 0,movey = 0;    
  11. function movead()    
  12. {    
  13.         var divObj = document.getElementById("adid");    
  14.             
  15.         movexmovex = movex + x*5;    
  16.         moveymovey = movey + y*5;    
  17.             
  18.             
  19.         divObj.style.top = movey;    
  20.         divObj.style.left = movex;    
  21.             
  22.         if(movex+divObj.offsetWidth>=document.body.clientWidth)    
  23.                 x = -1;    
  24.         else if(movex<=0)    
  25.                 x = 1;    
  26.         if(movey+divObj.offsetHeight>=document.body.clientHeight)    
  27.                 y = -1;    
  28.         else if(movey <=0)    
  29.                 y = 1;    
  30. }    
  31. var timeid;    
  32.   
  33. function over()    
  34. {    
  35.         clearInterval(timeid);    
  36. }    
  37.   
  38. function out()    
  39. {    
  40.         fly();    
  41. }    
  42.   
  43. function fly()    
  44. {    
  45.         timeid = setInterval("movead()",10);    
  46. }    
  47. window.onload = function()    
  48. {    
  49.         fly();    
  50. }    
  51.   
  52. function closead()    
  53. {    
  54.         var divObj = document.getElementById("adid");    
  55.         divObj.style.display = "none";    
  56.             
  57.         over();    
  58. }    
  59. </script>    
  60.   
  61. </head>    
  62.   
  63. <body>    
  64. <input type="button" value="手动广告" onclick="movead()" /><br />    
  65. <div id="adid" style="position:absolute; top:0px; left:0px"  onmouseover="over()" onmouseout="out()"><a href="http://www.sss.com.cn" target="_blank"><img src="2.jpg" height="100px" width="150px" /></a><br/>    
  66. <a href="javascript:void(0)" onclick="closead()">关闭</a></div>    
  67.   
  68.   
  69.   
  70. <img src="1.jpg" height="600" width="700" border="2" />    
  71. </body>    
  72. </html>    
  73.   

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值