Posted By

a1ias on 07/28/11


Tagged

scripts


Versions (?)

Javascript snow


 / Published in: JavaScript
 

  1. <script language="javascript">
  2. // Set the number of snowflakes (more than 30 - 40 not recommended)
  3. var snowmax=20
  4. // Set the colors for the snow. Add as many colors as you like
  5. var snowcolor=new Array("#aaaacc","#ddddFF","#ccccDD")
  6. // Set the fonts, that create the snowflakes. Add as many fonts as you like
  7. var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS")
  8. // Set the letter that creates your snowflake (recommended:*)
  9. var snowletter="*"
  10. // Set the speed of sinking (recommended values range from 0.3 to 2)
  11. var sinkspeed=0.6
  12. // Set the maximal-size of your snowflaxes
  13. var snowmaxsize=22
  14. // Set the minimal-size of your snowflaxes
  15. var snowminsize=8
  16. // Set the snowing-zone
  17. // Set 1 for all-over-snowing, set 2 for left-side-snowing
  18. // Set 3 for center-snowing, set 4 for right-side-snowing
  19. var snowingzone=1
  20.  
  21. // Do not edit below this line
  22. var snow=new Array()
  23. var marginbottom
  24. var marginright
  25. var timer
  26. var i_snow=0
  27. var x_mv=new Array();
  28. var crds=new Array();
  29. var lftrght=new Array();
  30. var browserinfos=navigator.userAgent
  31. var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
  32. var ns6=document.getElementById&&!document.all
  33. var opera=browserinfos.match(/Opera/)
  34. var browserok=ie5||ns6||opera
  35.  
  36. function randommaker(range) {
  37. rand=Math.floor(range*Math.random())
  38. return rand
  39. }
  40.  
  41. function initsnow() {
  42. if (ie5 || opera) {
  43. marginbottom = document.body.clientHeight
  44. marginright = document.body.clientWidth
  45. }
  46. else if (ns6) {
  47. marginbottom = window.innerHeight
  48. marginright = window.innerWidth
  49. }
  50. var snowsizerange=snowmaxsize-snowminsize
  51. for (i=0;i<=snowmax;i++) {
  52. crds[i] = 0;
  53. lftrght[i] = Math.random()*15;
  54. x_mv[i] = 0.03 + Math.random()/10;
  55. snow[i]=document.getElementById("s"+i)
  56. snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
  57. snow[i].size=randommaker(snowsizerange)+snowminsize
  58. snow[i].style.fontSize=snow[i].size
  59. snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
  60. snow[i].sink=sinkspeed*snow[i].size/5
  61. if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
  62. if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
  63. if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
  64. if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
  65. snow[i].posy=randommaker(2*marginbottom-marginbottom-2*snow[i].size)
  66. snow[i].style.left=snow[i].posx
  67. snow[i].style.top=snow[i].posy
  68. }
  69. movesnow()
  70. }
  71.  
  72. function movesnow() {
  73. for (i=0;i<=snowmax;i++) {
  74. crds[i] += x_mv[i];
  75. snow[i].posy+=snow[i].sink
  76. snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i]);
  77. snow[i].style.top=snow[i].posy
  78.  
  79. if (snow[i].posy>=marginbottom-2*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){
  80. if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
  81. if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
  82. if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
  83. if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
  84. snow[i].posy=0
  85. }
  86. }
  87. var timer=setTimeout("movesnow()",50)
  88. }
  89.  
  90. for (i=0;i<=snowmax;i++) {
  91. document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
  92. }
  93. if (browserok) {
  94. window.onload=initsnow
  95. }
  96. </script>

Report this snippet  

You need to login to post a comment.