Advertisement
thesharwhal

Snow Effect

Jan 3rd, 2013
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. <!--
  2. paste this RIGHT AFTER <head>
  3. very important ^
  4. -->
  5.  
  6. <script type="text/javascript">
  7. // <![CDATA[
  8. var speed=33; // lower number for faster
  9. var flakes=100; // number of flakes
  10. var colour="#ffffff"; // colour of flakes
  11. var slush=20; // set to '0' for no slush or otherwise set to height at which slush melts
  12.  
  13. /***************************\
  14. * Let It Snow Effect *
  15. *(c)2004-11 mf2fm web-design*
  16. *http://cigerettes.tumblr.com*
  17. * http://www.mf2fm.com/rv *
  18. * DON'T EDIT BELOW THIS BOX *
  19. \***************************/
  20. var flks=new Array();
  21. var flkx=new Array();
  22. var flky=new Array();
  23. var fldy=new Array();
  24. var slss=new Array();
  25. var slsh=new Array();
  26. var swide, shigh, boddie;
  27. window.onload=function() { if (document.getElementById) {
  28. boddie=document.createElement("div");
  29. boddie.style.position="fixed";
  30. boddie.style.top="0px";
  31. boddie.style.left="0px";
  32. boddie.style.width="1px";
  33. boddie.style.height="1px";
  34. boddie.style.overflow="visible";
  35. boddie.style.backgroundColor="transparent";
  36. document.body.appendChild(boddie);
  37. set_width();
  38. for (var i=0; i<flakes; i++) {
  39. flks[i]=createDiv(3, 3, colour);
  40. flkx[i]=3*Math.floor(Math.random()*swide/3);
  41. flky[i]=Math.floor(Math.random()*shigh);
  42. fldy[i]=2+Math.floor(Math.random()*4);
  43. flks[i].style.left=flkx[i]+"px";
  44. flks[i].style.top=flky[i]+"px";
  45. boddie.appendChild(flks[i]);
  46. }
  47. setInterval("let_it_snow()", speed);
  48. }}
  49.  
  50. function createDiv(height, width, colour) {
  51. var div=document.createElement("div");
  52. div.style.position="absolute";
  53. div.style.height=height+"px";
  54. div.style.width=width+"px";
  55. div.style.overflow="hidden";
  56. div.style.backgroundColor=colour;
  57. return (div);
  58. }
  59.  
  60. window.onresize=set_width;
  61. function set_width() {
  62. var sw_min=999999;
  63. var sh_min=999999;
  64. if (document.documentElement && document.documentElement.clientWidth) {
  65. if (document.documentElement.clientWidth>0) sw_min=document.documentElement.clientWidth;
  66. if (document.documentElement.clientHeight>0) sh_min=document.documentElement.clientHeight;
  67. }
  68. if (typeof(self.innerWidth)!="undefined" && self.innerWidth) {
  69. if (self.innerWidth>0 && self.innerWidth<sw_min) sw_min=self.innerWidth;
  70. if (self.innerHeight>0 && self.innerHeight<sh_min) sh_min=self.innerHeight;
  71. }
  72. if (document.body.clientWidth) {
  73. if (document.body.clientWidth>0 && document.body.clientWidth<sw_min) sw_min=document.body.clientWidth;
  74. if (document.body.clientHeight>0 && document.body.clientHeight<sh_min) sh_min=document.body.clientHeight;
  75. }
  76. if (sw_min==999999 || sh_min==999999) {
  77. sw_min=800;
  78. sh_min=600;
  79. }
  80. swide=sw_min-3;
  81. shigh=sh_min;
  82. if (slush) {
  83. if (swide/3>slss.length) for (i=slss.length; i<swide/3; i++) {
  84. if (!slsh[i]) slsh[i]=3;
  85. slss[i]=createDiv(slsh[i], 3, colour);
  86. boddie.appendChild(slss[i]);
  87. }
  88. for (i=0; i<swide/3; i++) {
  89. slss[i].style.height=slsh[i]+"px";
  90. slss[i].style.top=shigh-slsh[i]+"px";
  91. slss[i].style.left=3*i+"px";
  92. }
  93. if (i<slss.length && slss[i].style.left!="-3px") for (; i<slss.length; i++) slss[i].style.left="-3px";
  94. }
  95. }
  96.  
  97. function let_it_snow(c) {
  98. var i, x, o=0, z=0;
  99. for (i=0; i<flakes; i++) {
  100. flky[i]+=fldy[i];
  101. x=Math.floor(flkx[i]/3);
  102. if (slush) {
  103. o+=slsh[x];
  104. if (flky[i]>=shigh-slsh[x]) {
  105. if (x<swide && slsh[x]>slsh[x+1]+3) x++;
  106. else if (x>0 && slsh[x]>slsh[x-1]+3) x--;
  107. slss[x].style.top=shigh-(slsh[x]+=3)+"px";
  108. slss[x].style.height=slsh[x]+"px";
  109. flky[i]=shigh;
  110. }
  111. }
  112. if (flky[i]>=shigh || flkx[i]>swide) {
  113. flky[i]=0;
  114. fldy[i]=2+Math.floor(Math.random()*4);
  115. flkx[i]=3*Math.floor(Math.random()*swide/3);
  116. flks[i].style.left=flkx[i]+"px";
  117. z++;
  118. }
  119. flks[i].style.top=flky[i]+"px";
  120. }
  121. if (o>flakes*slush) for (i=0; i<slsh.length; i++) if (slsh[i]>3) slsh[i]--;
  122. if (z || o>flakes*slush) set_width();
  123. }
  124. // ]]>
  125. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement