Advertisement
Guest User

Add Snow To Your Website HTML

a guest
Dec 19th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <script type="text/javascript">
  2.  
  3. /******************************************
  4. * Snow Effect Script- By Altan d.o.o. (http://www.altan.hr/snow/index.html)
  5. * Visit Dynamic Drive DHTML code library (http://www.dynamicdrive.com/) for full source code
  6. * Last updated Nov 9th, 05' by DD. This notice must stay intact for use
  7. ******************************************/
  8.  
  9. //Configure below to change URL path to the snow image
  10. var snowsrc="http://www.weebly.com/editor/uploads/3/8/4/9/38497201/custom_themes/299785452551106884/files/snow.gif?1419045585087"
  11. // Configure below to change number of snow to render
  12. var no = 10;
  13. // Configure whether snow should disappear after x seconds (0=never):
  14. var hidesnowtime = 0;
  15. // Configure how much snow should drop down before fading ("windowheight" or "pageheight")
  16. var snowdistance = "pageheight";
  17.  
  18. ///////////Stop Config//////////////////////////////////
  19.  
  20. var ie4up = (document.all) ? 1 : 0;
  21. var ns6up = (document.getElementById&&!document.all) ? 1 : 0;
  22.  
  23. function iecompattest(){
  24. return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  25. }
  26.  
  27. var dx, xp, yp; // coordinate and position variables
  28. var am, stx, sty; // amplitude and step variables
  29. var i, doc_width = 800, doc_height = 600;
  30.  
  31. if (ns6up) {
  32. doc_width = self.innerWidth;
  33. doc_height = self.innerHeight;
  34. } else if (ie4up) {
  35. doc_width = iecompattest().clientWidth;
  36. doc_height = iecompattest().clientHeight;
  37. }
  38.  
  39. dx = new Array();
  40. xp = new Array();
  41. yp = new Array();
  42. am = new Array();
  43. stx = new Array();
  44. sty = new Array();
  45. snowsrc=(snowsrc.indexOf("dynamicdrive.com")!=-1)? "snow.gif" : snowsrc
  46. for (i = 0; i < no; ++ i) {
  47. dx[i] = 0; // set coordinate variables
  48. xp[i] = Math.random()*(doc_width-50); // set position variables
  49. yp[i] = Math.random()*doc_height;
  50. am[i] = Math.random()*20; // set amplitude variables
  51. stx[i] = 0.02 + Math.random()/10; // set step variables
  52. sty[i] = 0.7 + Math.random(); // set step variables
  53. if (ie4up||ns6up) {
  54. if (i == 0) {
  55. document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><a href=\"http://dynamicdrive.com\"><img src='"+snowsrc+"' border=\"0\"><\/a><\/div>");
  56. } else {
  57. document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+snowsrc+"' border=\"0\"><\/div>");
  58. }
  59. }
  60. }
  61.  
  62. function snowIE_NS6() { // IE and NS6 main animation function
  63. doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
  64. doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")? iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
  65. for (i = 0; i < no; ++ i) { // iterate for every dot
  66. yp[i] += sty[i];
  67. if (yp[i] > doc_height-50) {
  68. xp[i] = Math.random()*(doc_width-am[i]-30);
  69. yp[i] = 0;
  70. stx[i] = 0.02 + Math.random()/10;
  71. sty[i] = 0.7 + Math.random();
  72. }
  73. dx[i] += stx[i];
  74. document.getElementById("dot"+i).style.top=yp[i]+"px";
  75. document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";
  76. }
  77. snowtimer=setTimeout("snowIE_NS6()", 10);
  78. }
  79.  
  80. function hidesnow(){
  81. if (window.snowtimer) clearTimeout(snowtimer)
  82. for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden"
  83. }
  84.  
  85.  
  86. if (ie4up||ns6up){
  87. snowIE_NS6();
  88. if (hidesnowtime>0)
  89. setTimeout("hidesnow()", hidesnowtime*1000)
  90. }
  91.  
  92. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement