DriftBox.js
上传用户:jisenq
上传日期:2014-06-29
资源大小:7216k
文件大小:2k
源码类别:

数据库编程

开发平台:

ASP/ASPX

  1. DriftBoxTF=navigator.javaEnabled()?true:false;
  2. var DriftBoxMin=2; var DriftBoxMax=5; var DriftBoxRe=2; var DriftBoxTime;
  3. function Chip(chipname,width,height)
  4. {
  5. this.named=chipname;
  6. this.vx=DriftBoxMin+DriftBoxMax*Math.random();
  7. this.vy=DriftBoxMin+DriftBoxMax*Math.random();
  8. this.w=width; this.h=height;
  9. this.xx=0;
  10. this.yy=0;
  11. this.DriftBoxTime=null;
  12. }
  13. function movechip(chipname) 
  14. {
  15. if(DriftBoxTF)
  16. {
  17. eval("chip="+chipname);
  18. if(DriftBoxStr)
  19. {
  20. pageX=window.pageXOffset;
  21. pageW=window.innerWidth;
  22. pageY=window.pageYOffset;
  23. pageH=window.innerHeight;
  24. }
  25. else
  26. {
  27. pageX=window.document.body.scrollLeft;
  28. pageW=window.document.body.offsetWidth-8;
  29. pageY=window.document.body.scrollTop;
  30. pageH=window.document.body.offsetHeight;
  31. }
  32. chip.xx=chip.xx+chip.vx;chip.yy=chip.yy+chip.vy;
  33. chip.vx+=DriftBoxRe*(Math.random()-0.5);
  34. chip.vy+=DriftBoxRe*(Math.random()-0.5);
  35. if(chip.vx>(DriftBoxMax+DriftBoxMin)) chip.vx=(DriftBoxMax+DriftBoxMin)*2-chip.vx;
  36. if(chip.vx<(-DriftBoxMax-DriftBoxMin)) chip.vx=(-DriftBoxMax-DriftBoxMin)*2-chip.vx;
  37. if(chip.vy>(DriftBoxMax+DriftBoxMin)) chip.vy=(DriftBoxMax+DriftBoxMin)*2-chip.vy;
  38. if(chip.vy<(-DriftBoxMax-DriftBoxMin)) chip.vy=(-DriftBoxMax-DriftBoxMin)*2-chip.vy;
  39. if(chip.xx<=pageX)
  40. {
  41. chip.xx=pageX;chip.vx=DriftBoxMin+DriftBoxMax*Math.random();
  42.  }
  43. if(chip.xx>=pageX+pageW-chip.w)
  44. {
  45. chip.xx=pageX+pageW-chip.w;
  46. chip.vx=-DriftBoxMin-DriftBoxMax*Math.random();
  47.  }
  48. if(chip.yy<=pageY){
  49. chip.yy=pageY;
  50. chip.vy=DriftBoxMin+DriftBoxMax*Math.random();
  51. }
  52. if(chip.yy>=pageY+pageH-chip.h){
  53. chip.yy=pageY+pageH-chip.h;
  54. chip.vy=-DriftBoxMin-DriftBoxMax*Math.random();
  55. }
  56. if(DriftBoxStr)
  57. {
  58. eval('document.'+chip.named+'.top ='+chip.yy);
  59. eval('document.'+chip.named+'.left='+chip.xx);
  60.  }
  61. else
  62. {
  63. eval('document.all.'+chip.named+'.style.pixelLeft='+chip.xx);
  64. eval('document.all.'+chip.named+'.style.pixelTop ='+chip.yy);
  65.  }
  66. chip.DriftBoxTime=setTimeout("movechip('"+chip.named+"')",100);
  67. }
  68. }
  69. function DriftBoxSM(chipname)
  70. if(DriftBoxTF)
  71. {
  72. eval("chip="+chipname);
  73. if(chip.DriftBoxTime!=null)
  74. {
  75. clearTimeout(chip.DriftBoxTime)
  76. }
  77. }
  78. }
  79. var DriftBox;
  80. function DriftBox() 
  81. {
  82. DriftBox=new Chip("DriftBox",60,80);
  83. if(DriftBoxTF)
  84. {
  85. movechip("DriftBox");
  86.  }
  87. }
  88. window.onload=DriftBox;