Advertisement
reijeo

sparkle trail

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