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