xoxjesse143xox

MULTI COLORED SPARKLES

Aug 17th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. <script type="text/javascript">
  2.  
  3. // <![CDATA[
  4.  
  5. var colour="random"; // in addition to "random" can be set to any valid colour eg "#f0f" or "red"
  6.  
  7. var sparkles=50;
  8.  
  9.  
  10.  
  11.  
  12.  
  13. /****************************
  14.  
  15. * Tinkerbell Magic Sparkle *
  16.  
  17. *(c)2005-11 mf2fm web-design*
  18.  
  19. * http://www.mf2fm.com/rv *
  20.  
  21. * DON'T EDIT BELOW THIS BOX *
  22.  
  23. ****************************/
  24.  
  25. var x=ox=400;
  26.  
  27. var y=oy=300;
  28.  
  29. var swide=800;
  30.  
  31. var shigh=600;
  32.  
  33. var sleft=sdown=0;
  34.  
  35. var tiny=new Array();
  36.  
  37. var star=new Array();
  38.  
  39. var starv=new Array();
  40.  
  41. var starx=new Array();
  42.  
  43. var stary=new Array();
  44.  
  45. var tinyx=new Array();
  46.  
  47. var tinyy=new Array();
  48.  
  49. var tinyv=new Array();
  50.  
  51.  
  52.  
  53. window.onload=function() { if (document.getElementById) {
  54.  
  55. var i, rats, rlef, rdow;
  56.  
  57. for (var i=0; i<sparkles; i++) {
  58.  
  59. var rats=createDiv(3, 3);
  60.  
  61. rats.style.visibility="hidden";
  62.  
  63. document.body.appendChild(tiny[i]=rats);
  64.  
  65. starv[i]=0;
  66.  
  67. tinyv[i]=0;
  68.  
  69. var rats=createDiv(5, 5);
  70.  
  71. rats.style.backgroundColor="transparent";
  72.  
  73. rats.style.visibility="hidden";
  74.  
  75. var rlef=createDiv(1, 5);
  76.  
  77. var rdow=createDiv(5, 1);
  78.  
  79. rats.appendChild(rlef);
  80.  
  81. rats.appendChild(rdow);
  82.  
  83. rlef.style.top="2px";
  84.  
  85. rlef.style.left="0px";
  86.  
  87. rdow.style.top="0px";
  88.  
  89. rdow.style.left="2px";
  90.  
  91. document.body.appendChild(star[i]=rats);
  92.  
  93. }
  94.  
  95. set_width();
  96.  
  97. sparkle();
  98.  
  99. }}
  100.  
  101.  
  102.  
  103. function sparkle() {
  104.  
  105. var c;
  106.  
  107. if (x!=ox || y!=oy) {
  108.  
  109. ox=x;
  110.  
  111. oy=y;
  112.  
  113. for (c=0; c<sparkles; c++) if (!starv[c]) {
  114.  
  115. star[c].style.left=(starx[c]=x)+"px";
  116.  
  117. star[c].style.top=(stary[c]=y)+"px";
  118.  
  119. star[c].style.clip="rect(0px, 5px, 5px, 0px)";
  120.  
  121. star[c].childNodes[0].style.backgroundColor=star[c].childNodes[1].style.backgroundColor=(colour=="random")?newColour():colour;
  122.  
  123. star[c].style.visibility="visible";
  124.  
  125. starv[c]=50;
  126.  
  127. break;
  128.  
  129. }
  130.  
  131. }
  132.  
  133. for (c=0; c<sparkles; c++) {
  134.  
  135. if (starv[c]) update_star(c);
  136.  
  137. if (tinyv[c]) update_tiny(c);
  138.  
  139. }
  140.  
  141. setTimeout("sparkle()", 40);
  142.  
  143. }
  144.  
  145.  
  146.  
  147. function update_star(i) {
  148.  
  149. if (--starv[i]==25) star[i].style.clip="rect(1px, 4px, 4px, 1px)";
  150.  
  151. if (starv[i]) {
  152.  
  153. stary[i]+=1+Math.random()*3;
  154.  
  155. if (stary[i]<shigh+sdown && starx[i]>0) {
  156.  
  157. star[i].style.top=stary[i]+"px";
  158.  
  159. starx[i]+=(i%5-2)/5;
  160.  
  161. star[i].style.left=starx[i]+"px";
  162.  
  163. }
  164.  
  165. else {
  166.  
  167. star[i].style.visibility="hidden";
  168.  
  169. starv[i]=0;
  170.  
  171. return;
  172.  
  173. }
  174.  
  175. }
  176.  
  177. else {
  178.  
  179. tinyv[i]=50;
  180.  
  181. tiny[i].style.top=(tinyy[i]=stary[i])+"px";
  182.  
  183. tiny[i].style.left=(tinyx[i]=starx[i])+"px";
  184.  
  185. tiny[i].style.width="2px";
  186.  
  187. tiny[i].style.height="2px";
  188.  
  189. tiny[i].style.backgroundColor=star[i].childNodes[0].style.backgroundColor;
  190.  
  191. star[i].style.visibility="hidden";
  192.  
  193. tiny[i].style.visibility="visible"
  194.  
  195. }
  196.  
  197. }
  198.  
  199.  
  200.  
  201. function update_tiny(i) {
  202.  
  203. if (--tinyv[i]==25) {
  204.  
  205. tiny[i].style.width="1px";
  206.  
  207. tiny[i].style.height="1px";
  208.  
  209. }
  210.  
  211. if (tinyv[i]) {
  212.  
  213. tinyy[i]+=1+Math.random()*3;
  214.  
  215. if (tinyy[i]<shigh+sdown && tinyx[i]>0) {
  216.  
  217. tiny[i].style.top=tinyy[i]+"px";
  218.  
  219. tinyx[i]+=(i%5-2)/5;
  220.  
  221. tiny[i].style.left=tinyx[i]+"px";
  222.  
  223. }
  224.  
  225. else {
  226.  
  227. tiny[i].style.visibility="hidden";
  228.  
  229. tinyv[i]=0;
  230.  
  231. return;
  232.  
  233. }
  234.  
  235. }
  236.  
  237. else tiny[i].style.visibility="hidden";
  238.  
  239. }
  240.  
  241.  
  242.  
  243. document.onmousemove=mouse;
  244.  
  245. function mouse(e) {
  246.  
  247. set_scroll();
  248.  
  249. y=(e)?e.pageY:event.y+sdown;
  250.  
  251. x=(e)?e.pageX:event.x+sleft;
  252.  
  253. }
  254.  
  255.  
  256.  
  257. function set_scroll() {
  258.  
  259. if (typeof(self.pageYOffset)=="number") {
  260.  
  261. sdown=self.pageYOffset;
  262.  
  263. sleft=self.pageXOffset;
  264.  
  265. }
  266.  
  267. else if (document.body.scrollTop || document.body.scrollLeft) {
  268.  
  269. sdown=document.body.scrollTop;
  270.  
  271. sleft=document.body.scrollLeft;
  272.  
  273. }
  274.  
  275. else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
  276.  
  277. sleft=document.documentElement.scrollLeft;
  278.  
  279. sdown=document.documentElement.scrollTop;
  280.  
  281. }
  282.  
  283. else {
  284.  
  285. sdown=0;
  286.  
  287. sleft=0;
  288.  
  289. }
  290.  
  291. }
  292.  
  293.  
  294.  
  295. window.onresize=set_width;
  296.  
  297. function set_width() {
  298.  
  299. var sw_min=999999;
  300.  
  301. var sh_min=999999;
  302.  
  303. if (document.documentElement && document.documentElement.clientWidth) {
  304.  
  305. if (document.documentElement.clientWidth>0) sw_min=document.documentElement.clientWidth;
  306.  
  307. if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight;
  308.  
  309. }
  310.  
  311. if (typeof(self.innerWidth)!="undefined" && self.innerWidth) {
  312.  
  313. if (self.innerWidth>0 && self.innerWidth<sw_min) sw_min=self.innerWidth;
  314.  
  315. if (self.innerHeight>0 && self.innerHeight<sh_min) sh_min=self.innerHeight;
  316.  
  317. }
  318.  
  319. if (document.body.clientWidth) {
  320.  
  321. if (document.body.clientWidth>0 && document.body.clientWidth<sw_min) sw_min=document.body.clientWidth;
  322.  
  323. if (document.body.clientHeight>0 && document.body.clientHeight<sh_min) sh_min=document.body.clientHeight;
  324.  
  325. }
  326.  
  327. if (sw_min==999999 || sh_min==999999) {
  328.  
  329. sw_min=800;
  330.  
  331. sh_min=600;
  332.  
  333. }
  334.  
  335. swide=sw_min;
  336.  
  337. shigh=sh_min;
  338.  
  339. }
  340.  
  341.  
  342.  
  343. function createDiv(height, width) {
  344.  
  345. var div=document.createElement("div");
  346.  
  347. div.style.position="absolute";
  348.  
  349. div.style.height=height+"px";
  350.  
  351. div.style.width=width+"px";
  352.  
  353. div.style.overflow="hidden";
  354.  
  355. return (div);
  356.  
  357. }
  358.  
  359.  
  360.  
  361. function newColour() {
  362.  
  363. var c=new Array();
  364.  
  365. c[0]=255;
  366.  
  367. c[1]=Math.floor(Math.random()*256);
  368.  
  369. c[2]=Math.floor(Math.random()*(256-c[1]/2));
  370.  
  371. c.sort(function(){return (0.5 - Math.random());});
  372.  
  373. return ("rgb("+c[0]+", "+c[1]+", "+c[2]+")");
  374.  
  375. }
  376.  
  377. // ]]>
  378.  
  379. </script>
Advertisement
Add Comment
Please, Sign In to add comment