|
| 1 | + var colour="random"; // "random" can be replaced with any valid colour ie: "red"... |
| 2 | + var sparkles=100;// increase of decrease for number of sparkles falling |
| 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 | + colours=new Array('#ff0000','#00ff00','#ffffff','#ff00ff','#ffa500','#ffff00','#00ff00','#ffffff','ff00ff') |
| 19 | + |
| 20 | + n = 10; |
| 21 | + y = 0; |
| 22 | + x = 0; |
| 23 | + n6=(document.getElementById&&!document.all); |
| 24 | + ns=(document.layers); |
| 25 | + ie=(document.all); |
| 26 | + d=(ns||ie)?'document.':'document.getElementById("'; |
| 27 | + a=(ns||n6)?'':'all.'; |
| 28 | + n6r=(n6)?'")':''; |
| 29 | + s=(ns)?'':'.style'; |
| 30 | + |
| 31 | + if (ns){ |
| 32 | + for (i = 0; i < n; i++) |
| 33 | + document.write('<layer name="dots'+i+'" top=0 left=0 width='+i/2+' height='+i/2+' bgcolor=#ff0000></layer>'); |
| 34 | + } |
| 35 | + |
| 36 | + if (ie) |
| 37 | + document.write('<div id="con" style="position:absolute;top:0px;left:0px"><div style="position:relative">'); |
| 38 | + |
| 39 | + if (ie||n6){ |
| 40 | + for (i = 0; i < n; i++) |
| 41 | + document.write('<div id="dots'+i+'" style="position:absolute;top:0px;left:0px;width:'+i/2+'px;height:'+i/2+'px;background:#ff0000;font-size:'+i/2+'"></div>'); |
| 42 | + } |
| 43 | + |
| 44 | + if (ie) |
| 45 | + document.write('</div></div>'); |
| 46 | + (ns||n6)?window.captureEvents(Event.MOUSEMOVE):0; |
| 47 | + |
| 48 | + function Mouse(evnt){ |
| 49 | + |
| 50 | + y = (ns||n6)?evnt.pageY+4 - window.pageYOffset:event.y+4; |
| 51 | + x = (ns||n6)?evnt.pageX+1:event.x+1; |
| 52 | + } |
| 53 | + |
| 54 | + (ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse; |
| 55 | + |
| 56 | + function animate(){ |
| 57 | + |
| 58 | + o=(ns||n6)?window.pageYOffset:0; |
| 59 | + |
| 60 | + if (ie)con.style.top=document.body.scrollTop + 'px'; |
| 61 | + |
| 62 | + for (i = 0; i < n; i++){ |
| 63 | + |
| 64 | + var temp1 = eval(d+a+"dots"+i+n6r+s); |
| 65 | + |
| 66 | + randcolours = colours[Math.floor(Math.random()*colours.length)]; |
| 67 | + |
| 68 | + (ns)?temp1.bgColor = randcolours:temp1.background = randcolours; |
| 69 | + |
| 70 | + if (i < n-1){ |
| 71 | + |
| 72 | + var temp2 = eval(d+a+"dots"+(i+1)+n6r+s); |
| 73 | + temp1.top = parseInt(temp2.top) + 'px'; |
| 74 | + temp1.left = parseInt(temp2.left) + 'px'; |
| 75 | + |
| 76 | + } |
| 77 | + else{ |
| 78 | + |
| 79 | + temp1.top = y+o + 'px'; |
| 80 | + temp1.left = x + 'px'; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + setTimeout("animate()",10); |
| 85 | + } |
| 86 | + |
| 87 | + animate(); |
| 88 | + |
| 89 | + window.onload=function() { if (document.getElementById) { |
| 90 | + var i, rats, rlef, rdow; |
| 91 | + for (var i=0; i<sparkles; i++) { |
| 92 | + var rats=createDiv(3, 3); |
| 93 | + rats.style.visibility="hidden"; |
| 94 | + rats.style.zIndex="999"; |
| 95 | + document.body.appendChild(tiny[i]=rats); |
| 96 | + starv[i]=0; |
| 97 | + tinyv[i]=0; |
| 98 | + var rats=createDiv(5, 5); |
| 99 | + rats.style.backgroundColor="transparent"; |
| 100 | + rats.style.visibility="hidden"; |
| 101 | + rats.style.zIndex="999"; |
| 102 | + var rlef=createDiv(1, 5); |
| 103 | + var rdow=createDiv(5, 1); |
| 104 | + rats.appendChild(rlef); |
| 105 | + rats.appendChild(rdow); |
| 106 | + rlef.style.top="2px"; |
| 107 | + rlef.style.left="0px"; |
| 108 | + rdow.style.top="0px"; |
| 109 | + rdow.style.left="2px"; |
| 110 | + document.body.appendChild(star[i]=rats); |
| 111 | + } |
| 112 | + set_width(); |
| 113 | + sparkle(); |
| 114 | + }} |
| 115 | + |
| 116 | + function sparkle() { |
| 117 | + var c; |
| 118 | + if (Math.abs(x-ox)>1 || Math.abs(y-oy)>1) { |
| 119 | + ox=x; |
| 120 | + oy=y; |
| 121 | + for (c=0; c<sparkles; c++) if (!starv[c]) { |
| 122 | + star[c].style.left=(starx[c]=x)+"px"; |
| 123 | + star[c].style.top=(stary[c]=y+1)+"px"; |
| 124 | + star[c].style.clip="rect(0px, 5px, 5px, 0px)"; |
| 125 | + star[c].childNodes[0].style.backgroundColor=star[c].childNodes[1].style.backgroundColor=(colour=="random")?newColour():colour; |
| 126 | + star[c].style.visibility="visible"; |
| 127 | + starv[c]=50; |
| 128 | + break; |
| 129 | + } |
| 130 | + } |
| 131 | + for (c=0; c<sparkles; c++) { |
| 132 | + if (starv[c]) update_star(c); |
| 133 | + if (tinyv[c]) update_tiny(c); |
| 134 | + } |
| 135 | + setTimeout("sparkle()", 40); |
| 136 | + } |
| 137 | + |
| 138 | + function update_star(i) { |
| 139 | + if (--starv[i]==25) star[i].style.clip="rect(1px, 4px, 4px, 1px)"; |
| 140 | + if (starv[i]) { |
| 141 | + stary[i]+=1+Math.random()*3; |
| 142 | + starx[i]+=(i%5-2)/5; |
| 143 | + if (stary[i]<shigh+sdown) { |
| 144 | + star[i].style.top=stary[i]+"px"; |
| 145 | + star[i].style.left=starx[i]+"px"; |
| 146 | + } |
| 147 | + else { |
| 148 | + star[i].style.visibility="hidden"; |
| 149 | + starv[i]=0; |
| 150 | + return; |
| 151 | + } |
| 152 | + } |
| 153 | + else { |
| 154 | + tinyv[i]=50; |
| 155 | + tiny[i].style.top=(tinyy[i]=stary[i])+"px"; |
| 156 | + tiny[i].style.left=(tinyx[i]=starx[i])+"px"; |
| 157 | + tiny[i].style.width="2px"; |
| 158 | + tiny[i].style.height="2px"; |
| 159 | + tiny[i].style.backgroundColor=star[i].childNodes[0].style.backgroundColor; |
| 160 | + star[i].style.visibility="hidden"; |
| 161 | + tiny[i].style.visibility="visible" |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + function update_tiny(i) { |
| 166 | + if (--tinyv[i]==25) { |
| 167 | + tiny[i].style.width="1px"; |
| 168 | + tiny[i].style.height="1px"; |
| 169 | + } |
| 170 | + if (tinyv[i]) { |
| 171 | + tinyy[i]+=1+Math.random()*3; |
| 172 | + tinyx[i]+=(i%5-2)/5; |
| 173 | + if (tinyy[i]<shigh+sdown) { |
| 174 | + tiny[i].style.top=tinyy[i]+"px"; |
| 175 | + tiny[i].style.left=tinyx[i]+"px"; |
| 176 | + } |
| 177 | + else { |
| 178 | + tiny[i].style.visibility="hidden"; |
| 179 | + tinyv[i]=0; |
| 180 | + return; |
| 181 | + } |
| 182 | + } |
| 183 | + else tiny[i].style.visibility="hidden"; |
| 184 | + } |
| 185 | + |
| 186 | + document.onmousemove=mouse; |
| 187 | + function mouse(e) { |
| 188 | + if (e) { |
| 189 | + y=e.pageY; |
| 190 | + x=e.pageX; |
| 191 | + } |
| 192 | + else { |
| 193 | + set_scroll(); |
| 194 | + y=event.y+sdown; |
| 195 | + x=event.x+sleft; |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + window.onscroll=set_scroll; |
| 200 | + function set_scroll() { |
| 201 | + if (typeof(self.pageYOffset)=='number') { |
| 202 | + sdown=self.pageYOffset; |
| 203 | + sleft=self.pageXOffset; |
| 204 | + } |
| 205 | + else if (document.body && (document.body.scrollTop || document.body.scrollLeft)) { |
| 206 | + sdown=document.body.scrollTop; |
| 207 | + sleft=document.body.scrollLeft; |
| 208 | + } |
| 209 | + else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) { |
| 210 | + sleft=document.documentElement.scrollLeft; |
| 211 | + sdown=document.documentElement.scrollTop; |
| 212 | + } |
| 213 | + else { |
| 214 | + sdown=0; |
| 215 | + sleft=0; |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + window.onresize=set_width; |
| 220 | + function set_width() { |
| 221 | + var sw_min=999999; |
| 222 | + var sh_min=999999; |
| 223 | + if (document.documentElement && document.documentElement.clientWidth) { |
| 224 | + if (document.documentElement.clientWidth>0) sw_min=document.documentElement.clientWidth; |
| 225 | + if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight; |
| 226 | + } |
| 227 | + if (typeof(self.innerWidth)=='number' && self.innerWidth) { |
| 228 | + if (self.innerWidth>0 && self.innerWidth<sw_min) sw_min=self.innerWidth; |
| 229 | + if (self.innerHeight>0 && self.innerHeight<sh_min) sh_min=self.innerHeight; |
| 230 | + } |
| 231 | + if (document.body.clientWidth) { |
| 232 | + if (document.body.clientWidth>0 && document.body.clientWidth<sw_min) sw_min=document.body.clientWidth; |
| 233 | + if (document.body.clientHeight>0 && document.body.clientHeight<sh_min) sh_min=document.body.clientHeight; |
| 234 | + } |
| 235 | + if (sw_min==999999 || sh_min==999999) { |
| 236 | + sw_min=800; |
| 237 | + sh_min=600; |
| 238 | + } |
| 239 | + swide=sw_min; |
| 240 | + shigh=sh_min; |
| 241 | + } |
| 242 | + |
| 243 | + function createDiv(height, width) { |
| 244 | + var div=document.createElement("div"); |
| 245 | + div.style.position="absolute"; |
| 246 | + div.style.height=height+"px"; |
| 247 | + div.style.width=width+"px"; |
| 248 | + div.style.overflow="hidden"; |
| 249 | + return (div); |
| 250 | + } |
| 251 | + |
| 252 | + function newColour() { |
| 253 | + var c=new Array(); |
| 254 | + c[0]=255; |
| 255 | + c[1]=Math.floor(Math.random()*256); |
| 256 | + c[2]=Math.floor(Math.random()*(256-c[1]/2)); |
| 257 | + c.sort(function(){return (0.5 - Math.random());}); |
| 258 | + return ("rgb("+c[0]+", "+c[1]+", "+c[2]+")"); |
| 259 | + } |
0 commit comments