trail.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // <![CDATA[
  2. var colour="random"; // in addition to "random" can be set to any valid colour eg "#f0f" or "red"
  3. var sparkles=50;
  4. /****************************
  5. * Tinkerbell Magic Sparkle *
  6. *(c)2005-13 mf2fm web-design*
  7. * http://www.mf2fm.com/rv *
  8. * DON'T EDIT BELOW THIS BOX *
  9. ****************************/
  10. var x=ox=400;
  11. var y=oy=300;
  12. var swide=800;
  13. var shigh=600;
  14. var sleft=sdown=0;
  15. var tiny=new Array();
  16. var star=new Array();
  17. var starv=new Array();
  18. var starx=new Array();
  19. var stary=new Array();
  20. var tinyx=new Array();
  21. var tinyy=new Array();
  22. var tinyv=new Array();
  23. window.onload=function() { if (document.getElementById) {
  24. var i, rats, rlef, rdow;
  25. for (var i=0; i<sparkles; i++) {
  26. var rats=createDiv(3, 3);
  27. rats.style.visibility="hidden";
  28. rats.style.zIndex="999";
  29. document.body.appendChild(tiny[i]=rats);
  30. starv[i]=0;
  31. tinyv[i]=0;
  32. var rats=createDiv(5, 5);
  33. rats.style.backgroundColor="transparent";
  34. rats.style.visibility="hidden";
  35. rats.style.zIndex="999";
  36. var rlef=createDiv(1, 5);
  37. var rdow=createDiv(5, 1);
  38. rats.appendChild(rlef);
  39. rats.appendChild(rdow);
  40. rlef.style.top="2px";
  41. rlef.style.left="0px";
  42. rdow.style.top="0px";
  43. rdow.style.left="2px";
  44. document.body.appendChild(star[i]=rats);
  45. }
  46. set_width();
  47. sparkle();
  48. }}
  49. function sparkle() {
  50. var c;
  51. if (Math.abs(x-ox)>1 || Math.abs(y-oy)>1) {
  52. ox=x;
  53. oy=y;
  54. for (c=0; c<sparkles; c++) if (!starv[c]) {
  55. star[c].style.left=(starx[c]=x)+"px";
  56. star[c].style.top=(stary[c]=y+1)+"px";
  57. star[c].style.clip="rect(0px, 5px, 5px, 0px)";
  58. star[c].childNodes[0].style.backgroundColor=star[c].childNodes[1].style.backgroundColor=(colour=="random")?newColour():colour;
  59. star[c].style.visibility="visible";
  60. starv[c]=50;
  61. break;
  62. }
  63. }
  64. for (c=0; c<sparkles; c++) {
  65. if (starv[c]) update_star(c);
  66. if (tinyv[c]) update_tiny(c);
  67. }
  68. setTimeout("sparkle()", 40);
  69. }
  70. function update_star(i) {
  71. if (--starv[i]==25) star[i].style.clip="rect(1px, 4px, 4px, 1px)";
  72. if (starv[i]) {
  73. stary[i]+=1+Math.random()*3;
  74. starx[i]+=(i%5-2)/5;
  75. if (stary[i]<shigh+sdown) {
  76. star[i].style.top=stary[i]+"px";
  77. star[i].style.left=starx[i]+"px";
  78. }
  79. else {
  80. star[i].style.visibility="hidden";
  81. starv[i]=0;
  82. return;
  83. }
  84. }
  85. else {
  86. tinyv[i]=50;
  87. tiny[i].style.top=(tinyy[i]=stary[i])+"px";
  88. tiny[i].style.left=(tinyx[i]=starx[i])+"px";
  89. tiny[i].style.width="2px";
  90. tiny[i].style.height="2px";
  91. tiny[i].style.backgroundColor=star[i].childNodes[0].style.backgroundColor;
  92. star[i].style.visibility="hidden";
  93. tiny[i].style.visibility="visible";
  94. }
  95. }
  96. function update_tiny(i) {
  97. if (--tinyv[i]==25) {
  98. tiny[i].style.width="1px";
  99. tiny[i].style.height="1px";
  100. }
  101. if (tinyv[i]) {
  102. tinyy[i]+=1+Math.random()*3;
  103. tinyx[i]+=(i%5-2)/5;
  104. if (tinyy[i]<shigh+sdown) {
  105. tiny[i].style.top=tinyy[i]+"px";
  106. tiny[i].style.left=tinyx[i]+"px";
  107. }
  108. else {
  109. tiny[i].style.visibility="hidden";
  110. tinyv[i]=0;
  111. return;
  112. }
  113. }
  114. else tiny[i].style.visibility="hidden";
  115. }
  116. document.onmousemove=mouse;
  117. function mouse(e) {
  118. if (e) {
  119. y=e.pageY;
  120. x=e.pageX;
  121. }
  122. else {
  123. set_scroll();
  124. y=event.y+sdown;
  125. x=event.x+sleft;
  126. }
  127. }
  128. window.onscroll=set_scroll;
  129. function set_scroll() {
  130. if (typeof(self.pageYOffset)=='number') {
  131. sdown=self.pageYOffset;
  132. sleft=self.pageXOffset;
  133. }
  134. else if (document.body && (document.body.scrollTop || document.body.scrollLeft)) {
  135. sdown=document.body.scrollTop;
  136. sleft=document.body.scrollLeft;
  137. }
  138. else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
  139. sleft=document.documentElement.scrollLeft;
  140. sdown=document.documentElement.scrollTop;
  141. }
  142. else {
  143. sdown=0;
  144. sleft=0;
  145. }
  146. }
  147. window.onresize=set_width;
  148. function set_width() {
  149. var sw_min=999999;
  150. var sh_min=999999;
  151. if (document.documentElement && document.documentElement.clientWidth) {
  152. if (document.documentElement.clientWidth>0) sw_min=document.documentElement.clientWidth;
  153. if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight;
  154. }
  155. if (typeof(self.innerWidth)=='number' && self.innerWidth) {
  156. if (self.innerWidth>0 && self.innerWidth<sw_min) sw_min=self.innerWidth;
  157. if (self.innerHeight>0 && self.innerHeight<sh_min) sh_min=self.innerHeight;
  158. }
  159. if (document.body.clientWidth) {
  160. if (document.body.clientWidth>0 && document.body.clientWidth<sw_min) sw_min=document.body.clientWidth;
  161. if (document.body.clientHeight>0 && document.body.clientHeight<sh_min) sh_min=document.body.clientHeight;
  162. }
  163. if (sw_min==999999 || sh_min==999999) {
  164. sw_min=800;
  165. sh_min=600;
  166. }
  167. swide=sw_min;
  168. shigh=sh_min;
  169. }
  170. function createDiv(height, width) {
  171. var div=document.createElement("div");
  172. div.style.position="absolute";
  173. div.style.height=height+"px";
  174. div.style.width=width+"px";
  175. div.style.overflow="hidden";
  176. return (div);
  177. }
  178. function newColour() {
  179. var c=new Array();
  180. c[0]=255;
  181. c[1]=Math.floor(Math.random()*256);
  182. c[2]=Math.floor(Math.random()*(256-c[1]/2));
  183. c.sort(function(){return (0.5 - Math.random());});
  184. return ("rgb("+c[0]+", "+c[1]+", "+c[2]+")");
  185. }
  186. // ]]>