Public paste
Undefined
By: Guest | Date: Feb 1 2011 20:12 | Format: None | Expires: never | Size: 3.1 KB | Hits: 753

  1. var num_flakes = 30;
  2. var snowflakes = new Array("http://i.imgur.com/eUrqQ.png", "http://i.imgur.com/4JNTx.png", "http://i.imgur.com/c69hG.png");
  3.  
  4. // DOM test
  5. var aDOM = 0, ieDOM = 0, nsDOM = 0; var stdDOM = document.getElementById;
  6. if (stdDOM) aDOM = 1; else {ieDOM = document.all; if (ieDOM) aDOM = 1; else {
  7. var nsDOM = ((navigator.appName.indexOf('Netscape') != -1)
  8. && (parseInt(navigator.appVersion) ==4)); if (nsDOM) aDOM = 1;}}
  9. function findDOM(objectId, wS) {
  10. if (stdDOM) return wS ? document.getElementById(objectId).style:
  11. document.getElementById(objectId);
  12. if (ieDOM) return wS ? document.all[objectId].style: document.all[objectId];
  13. if (nsDOM) return document.layers[objectId];
  14. }
  15.  
  16. // window size tests
  17. function findLivePageWidth() {return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth :700;}function findLivePageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight :500;}
  18. function posX() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
  19. function posY() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
  20.  
  21. // make it snow
  22. var speed = 50;var movw = new Array();var movh = new Array();var move = new Array();var stepw = new Array();var steph = new Array();var posw = new Array();var posh = new Array();var dir = new Array();var winWidth;var winHeight;
  23. function startSnow() {winWidth = findLivePageWidth()-75;winHeight = findLivePageHeight()-50;
  24. for (var i = 0; i < num_flakes; i++){move[i] = 0;movh[i] = 12+ Math.random()*2;movw[i] = 11+ Math.random()*4;posw[i] = Math.random()*(winWidth-35)+12;posh[i] = Math.random()*winHeight;   stepw[i] = 0.02 + Math.random()/10;steph[i] = 0.7 + Math.random();dir[i] = (Math.random()>0.5)?1:-1;document.write('<div id="snow'+ i +'" style="position: absolute; z-index: '+ i +'; visibility:hidden; "><img src="'+snowflakes[Math.floor(Math.random()*snowflakes.length)]+ '" border="0"></div>');}setTimeout("moreSnow()", speed);}
  25. function moreSnow() {for (var i = 0; i < num_flakes; i++) {if (posh[i] > winHeight-50) {posw[i] = 10+ Math.random()*(winWidth-movw[i]-30);posh[i] = 0;dir[i]=(Math.random()<0.5)?1:-1;stepw[i] = 0.02 + Math.random()/9;steph[i] = 1.3 + Math.random();} move[i] += stepw[i] *dir[i]; if (Math.abs(move[i]) > 3) {dir[i]=-dir[i];   posh[i]+=Math.abs(movh[i]*move[i]);posw[i]+=movw[i]*move[i]; move[i]=0;} objstyle = findDOM('snow'+i,1); objstyle.left = (posX()+posw[i] + movw[i]*move[i])+'px'; objstyle.top = (posY()+posh[i] + movh[i]*(Math.abs(Math.cos(move[i])+move[i])))+'px';objstyle.visibility = 'visible';} setTimeout("moreSnow()", speed);}
  26. startSnow();