Advertisement
reijeo

shooting star/comet mf2fm

Jul 16th, 2022
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. <script type="text/javascript">
  2. // <![CDATA[
  3. var speed=25; // how fast - smaller is faster
  4. var how_often=10; // average time between re-appearances of a comet (in seconds)
  5. var how_many=10; // maximum number of comets in flight
  6. var colours=new Array("#ff0", "#f93", "#f60", "#e93", "#e94", "#da5", "#da6", "#cb7", "#cb8", "#cc9", "#dcb", "#ddd");
  7. // above line lists colours for the comet and its tail (can be as long or short as you like)
  8.  
  9. /****************************
  10. * Shooting Star/Comet Effect*
  11. *(c)2008-13 mf2fm web-design*
  12. * http://www.mf2fm.com/rv *
  13. * DON'T EDIT BELOW THIS BOX *
  14. ****************************/
  15.  
  16. var dx=new Array();
  17. var dy=new Array();
  18. var xpos=new Array();
  19. var ypos=new Array();
  20. var comets=new Array();
  21. var swide=800;
  22. var shigh=600;
  23. var tail=colours.length;
  24. var boddie=false;
  25.  
  26. function addLoadEvent(funky) {
  27. var oldonload=window.onload;
  28. if (typeof(oldonload)!='function') window.onload=funky;
  29. else window.onload=function() {
  30. if (oldonload) oldonload();
  31. funky();
  32. }
  33. }
  34.  
  35. addLoadEvent(whooosh);
  36.  
  37. function whooosh() { if (document.getElementById) {
  38. var i;
  39. boddie=document.createElement("div");
  40. boddie.style.position="fixed";
  41. boddie.style.top="0px";
  42. boddie.style.left="0px";
  43. boddie.style.overflow="visible";
  44. boddie.style.width="1px";
  45. boddie.style.height="1px";
  46. boddie.style.backgroundColor="transparent";
  47. document.body.appendChild(boddie);
  48. set_width();
  49. for (i=0; i<how_many; i++) {
  50. write_comet(i*tail);
  51. setTimeout('launch('+(i*tail)+')', Math.max(1000*i));
  52. }
  53. }}
  54.  
  55. function write_comet(a) {
  56. var i, s;
  57. for (i=0; i<tail; i++) {
  58. s=2+(i<tail/4)+2*!i;
  59. comets[i+a]=div(s, s);
  60. comets[i+a].style.backgroundColor=colours[i];
  61. boddie.appendChild(comets[i+a]);
  62. }
  63. }
  64.  
  65. function div(w, h) {
  66. var d=document.createElement("div");
  67. d.style.position="absolute";
  68. d.style.overflow="hidden";
  69. d.style.width=w+"px";
  70. d.style.height=h+"px";
  71. return (d);
  72. }
  73.  
  74. function stepthrough(a) {
  75. var i;
  76. if (Math.random()<0.008||ypos[a]+dy[a]<5||xpos[a]+dx[a]<5||xpos[a]+dx[a]>=swide-5||ypos[a]+dy[a]>=shigh-5) {
  77. for (i=0; i<tail; i++) setTimeout('comets['+(i+a)+'].style.visibility="hidden"', speed*(tail-i));
  78. setTimeout('launch('+a+')', Math.max(1000, 2000*Math.random()*how_often));
  79. }
  80. else setTimeout('stepthrough('+a+')', speed);
  81. for (i=tail-1; i>=0; i--) {
  82. if (i) {
  83. xpos[i+a]=xpos[i+a-1];
  84. ypos[i+a]=ypos[i+a-1];
  85. }
  86. else {
  87. xpos[i+a]+=dx[a];
  88. ypos[i+a]+=dy[a];
  89. }
  90. comets[i+a].style.left=xpos[i+a]+"px";
  91. comets[i+a].style.top=ypos[i+a]+"px";
  92. }
  93. }
  94.  
  95. function launch(a) {
  96. var i;
  97. dx[a]=(Math.random()>0.5?1:-1)*(1+Math.random()*3);
  98. dy[a]=(Math.random()>0.5?1:-1)*((7-dx[a])/3+Math.random()*(dx[a]+5)/3);
  99. xpos[a]=2*tail*dx[a]+Math.round(Math.random()*(swide-4*tail*dx[a]));
  100. ypos[a]=2*tail*dy[a]+Math.round(Math.random()*(shigh-4*tail*dy[a]));
  101. for (i=0; i<tail; i++) {
  102. xpos[i+a]=xpos[a];
  103. ypos[i+a]=ypos[a];
  104. comets[i+a].style.visibility="visible";
  105. }
  106. stepthrough(a);
  107. }
  108.  
  109. window.onresize=set_width;
  110. function set_width() {
  111. var sw_min=999999;
  112. var sh_min=999999;
  113. if (document.documentElement && document.documentElement.clientWidth) {
  114. if (document.documentElement.clientWidth>0) sw_min=document.documentElement.clientWidth;
  115. if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight;
  116. }
  117. if (typeof(self.innerWidth)!="undefined" && self.innerWidth) {
  118. if (self.innerWidth>0 && self.innerWidth<sw_min) sw_min=self.innerWidth;
  119. if (self.innerHeight>0 && self.innerHeight<sh_min) sh_min=self.innerHeight;
  120. }
  121. if (document.body.clientWidth) {
  122. if (document.body.clientWidth>0 && document.body.clientWidth<sw_min) sw_min=document.body.clientWidth;
  123. if (document.body.clientHeight>0 && document.body.clientHeight<sh_min) sh_min=document.body.clientHeight;
  124. }
  125. if (sw_min==999999 || sh_min==999999) {
  126. sw_min=800;
  127. sh_min=600;
  128. }
  129. swide=sw_min;
  130. shigh=sh_min;
  131. }
  132. // ]]>
  133. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement