home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 March / PCWorld_2007-03_cd.bin / komunikace / acehtml / acehtmlfreeware.exe / scriptdef / moveobj.js < prev    next >
Text File  |  2006-09-13  |  2KB  |  97 lines

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