Author: Not specified Language: javascript
Description: Not specified Timestamp: 2018-01-19 20:25:44 +0000
View raw paste Reply
  1. var colour="#00ffff";
  2. var sparkles=120;
  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].style.visibility="visible";
  53.       starv[c]=50;
  54.       break;
  55.     }
  56.   }
  57.   for (c=0; c<sparkles; c++) {
  58.     if (starv[c]) update_star(c);
  59.     if (tinyv[c]) update_tiny(c);
  60.   }
  61.   setTimeout("sparkle()", 40);
  62. }
  63.  
  64. function update_star(i) {
  65.   if (--starv[i]==25) star[i].style.clip="rect(1px, 4px, 4px, 1px)";
  66.   if (starv[i]) {
  67.     stary[i]+=1+Math.random()*3;
  68.     if (stary[i]<shigh+sdown) {
  69.       star[i].style.top=stary[i]+"px";
  70.       starx[i]+=(i%5-2)/5;
  71.       star[i].style.left=starx[i]+"px";
  72.     }
  73.     else {
  74.       star[i].style.visibility="hidden";
  75.       starv[i]=0;
  76.       return;
  77.     }
  78.   }
  79.   else {
  80.     tinyv[i]=50;
  81.     tiny[i].style.top=(tinyy[i]=stary[i])+"px";
  82.     tiny[i].style.left=(tinyx[i]=starx[i])+"px";
  83.     tiny[i].style.width="2px";
  84.     tiny[i].style.height="2px";
  85.     star[i].style.visibility="hidden";
  86.     tiny[i].style.visibility="visible"
  87.   }
  88. }
  89.  
  90. function update_tiny(i) {
  91.   if (--tinyv[i]==25) {
  92.     tiny[i].style.width="1px";
  93.     tiny[i].style.height="1px";
  94.   }
  95.   if (tinyv[i]) {
  96.     tinyy[i]+=1+Math.random()*3;
  97.     if (tinyy[i]<shigh+sdown) {
  98.       tiny[i].style.top=tinyy[i]+"px";
  99.       tinyx[i]+=(i%5-2)/5;
  100.       tiny[i].style.left=tinyx[i]+"px";
  101.     }
  102.     else {
  103.       tiny[i].style.visibility="hidden";
  104.       tinyv[i]=0;
  105.       return;
  106.     }
  107.   }
  108.   else tiny[i].style.visibility="hidden";
  109. }
  110.  
  111. document.onmousemove=mouse;
  112. function mouse(e) {
  113.   set_scroll();
  114.   y=(e)?e.pageY:event.y+sdown;
  115.   x=(e)?e.pageX:event.x+sleft;
  116. }
  117.  
  118. function set_scroll() {
  119.   if (typeof(self.pageYOffset)=="number") {
  120.     sdown=self.pageYOffset;
  121.     sleft=self.pageXOffset;
  122.   }
  123.   else if (document.body.scrollTop || document.body.scrollLeft) {
  124.     sdown=document.body.scrollTop;
  125.     sleft=document.body.scrollLeft;
  126.   }
  127.   else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
  128.     sleft=document.documentElement.scrollLeft;
  129.         sdown=document.documentElement.scrollTop;
  130.   }
  131.   else {
  132.     sdown=0;
  133.     sleft=0;
  134.   }
  135. }
  136.  
  137. window.onresize=set_width;
  138. function set_width() {
  139.   if (typeof(self.innerWidth)=="number") {
  140.     swide=self.innerWidth;
  141.     shigh=self.innerHeight;
  142.   }
  143.   else if (document.documentElement && document.documentElement.clientWidth) {
  144.     swide=document.documentElement.clientWidth;
  145.     shigh=document.documentElement.clientHeight;
  146.   }
  147.   else if (document.body.clientWidth) {
  148.     swide=document.body.clientWidth;
  149.     shigh=document.body.clientHeight;
  150.   }
  151. }
  152.  
  153. function createDiv(height, width) {
  154.   var div=document.createElement("div");
  155.   div.style.position="absolute";
  156.   div.style.height=height+"px";
  157.   div.style.width=width+"px";
  158.   div.style.overflow="hidden";
  159.   div.style.backgroundColor=colour;
  160.   return (div);
  161. }
View raw paste Reply