honghoavi

Merry Christmas - Snow

Dec 8th, 2012
4,367
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type='text/javascript'>
  2. //<![CDATA[
  3. var snowmax=100
  4. var snowcolor=new Array("#f2f8fa","#eff5f7","#dcedf1","#ffffff")
  5. var snowtype=new Array("Times","Arial","Times","Verdana")
  6. var snowletter="*"
  7. var sinkspeed=0.6
  8. var snowmaxsize=30
  9. var snowminsize=10
  10. // Set 1 for all-over-snowing, set 2 for left-side-snowing
  11. // Set 3 for center-snowing, set 4 for right-side-snowing
  12. var snowingzone=1
  13. // Do not edit below this line
  14. var snow=new Array()
  15. var marginbottom
  16. var marginright
  17. var timer
  18. var i_snow=0
  19. var x_mv=new Array();
  20. var crds=new Array();
  21. var lftrght=new Array();
  22. var browserinfos=navigator.userAgent
  23. var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
  24. var ns6=document.getElementById&&!document.all
  25. var opera=browserinfos.match(/Opera/)
  26. var browserok=ie5||ns6||opera
  27. function randommaker(range) {
  28.         rand=Math.floor(range*Math.random())
  29.     return rand
  30. }
  31. function initsnow() {
  32.         if (ie5 || opera) {
  33.                 marginbottom = document.body.scrollHeight
  34.                 marginright = document.body.clientWidth-15
  35.         }
  36.         else if (ns6) {
  37.                 marginbottom = document.body.scrollHeight
  38.                 marginright = window.innerWidth-15
  39.         }
  40.         var snowsizerange=snowmaxsize-snowminsize
  41.         for (i=0;i<=snowmax;i++) {
  42.                 crds[i] = 0;
  43.             lftrght[i] = Math.random()*15;
  44.             x_mv[i] = 0.03 + Math.random()/10;
  45.                 snow[i]=document.getElementById("s"+i)
  46.                 snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
  47.                 snow[i].size=randommaker(snowsizerange)+snowminsize
  48.                 snow[i].style.fontSize=snow[i].size+'px';
  49.                 snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
  50.                 snow[i].style.zIndex=1000
  51.                 snow[i].sink=sinkspeed*snow[i].size/5
  52.                 if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
  53.                 if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
  54.                 if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
  55.                 if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
  56.                 snow[i].posy=randommaker(2*marginbottom-marginbottom-2*snow[i].size)
  57.                 snow[i].style.left=snow[i].posx+'px';
  58.                 snow[i].style.top=snow[i].posy+'px';
  59.         }
  60.         movesnow()
  61. }
  62. function movesnow() {
  63.         for (i=0;i<=snowmax;i++) {
  64.                 crds[i] += x_mv[i];
  65.                 snow[i].posy+=snow[i].sink
  66.                 snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i])+'px';
  67.                 snow[i].style.top=snow[i].posy+'px';
  68.                 if (snow[i].posy>=marginbottom-2*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){
  69.                         if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
  70.                         if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
  71.                         if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
  72.                         if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
  73.                         snow[i].posy=0
  74.                 }
  75.         }
  76.         var timer=setTimeout("movesnow()",50)
  77. }
  78. for (i=0;i<=snowmax;i++) {
  79.         document.write("<span id='s"+i+"' style='position:absolute;top:-"+snowmaxsize+"'>"+snowletter+"</span>")
  80. }
  81. if (browserok) {
  82.         window.onload=initsnow
  83. }
  84. //]]>
  85. </script>
RAW Paste Data