Jump to content
xisto Community
Sign in to follow this  
iGuest

Snow Script,I works well both in IE and FireFox

Recommended Posts

I have seen the post here.http://forums.xisto.com/
It's really good,but it can't work in Mozilla FireFox,So I edit the code,and add a image.

Save the code as file snow.js



/*ä¸éŞsnow - Start*/var no = 10; // number of snowsvar speed = 20; // smaller number moves the snows fastervar heart = "images/snow.gif";var flag = new Array();var ns4up = (document.layers) ? 1 : 0; // browser sniffervar ie4up = (document.all) ? 1 : 0;var dom = (document.getElementById) ? 1 : 0;// coordinate and position variablesvar dx = new Array();var xp = new Array();var yp = new Array();// amplitude and step variablesvar amx = new Array();var amy = new Array();var stx = new Array();var sty = new Array();var i, doc_width = 800, doc_height = 600;if (ie4up) { doc_width = document.body.clientWidth; doc_height = document.body.scrollTop+document.body.clientHeight;}else { doc_width = window.innerWidth; doc_height = window.pageYOffset+window.innerHeight;}for (i = 0; i < no; ++ i) { dx[i] = 0; // set coordinate variables xp[i] = Math.random()*(doc_width-30)+10; // set position variables yp[i] = Math.random()*doc_height; amy[i] = 12+ Math.random()*20; // set amplitude variables amx[i] = 10+ Math.random()*40; stx[i] = 0.02 + Math.random()/10; // set step variables sty[i] = 0.7 + Math.random(); // set step variables flag[i] = (Math.random()>0.5)?1:0; if (ns4up) { // set layers  document.write("<layer id="dot"+ i +"" name="dot"+ i +"" left="150" top="150" visibility="show"><img src="" + heart+ "" border="0"></layer>"); } else{  document.write("<div id="dot"+ i +"" style="POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 150px; LEFT: 150px;"><img src="" + heart+ "" border="0"></div>"); }}function snow(){ for (i = 0; i < no; ++ i) { // iterate for every dot  if (yp[i] > doc_height-50) {   xp[i] = 10+ Math.random()*(doc_width-amx[i]-30);   yp[i] = 0;   stx[i] = 0.02 + Math.random()/10;   sty[i] = 0.7 + Math.random();   flag[i]=(Math.random()<0.5)?1:0;   if (ie4up) {    doc_width = document.body.clientWidth;    doc_height = document.body.clientHeight;   }   else{    doc_width = window.innerWidth;    doc_height = window.innerHeight;   }  }  if (flag[i])   dx[i] += stx[i];  else   dx[i] -= stx[i];  if (Math.abs(dx[i]) > Math.PI) {   yp[i]+=Math.abs(amy[i]*dx[i]);   xp[i]+=amx[i]*dx[i];   dx[i]=0;   flag[i]=!flag[i];  }  idot="dot"+i;  c=(dom)? document.getElementById(idot).style : (ie4up)? document.all[idot].style : (ns4up)? document.layers[idot] : "";  theTop=yp[i] + amy[i]*(Math.abs(Math.sin(dx[i])+dx[i]));  theLeft=xp[i] + amx[i]*dx[i];  if (ns4up) {   c.top=theTop;   c.left=theLeft;  }  else if(ie4up){   c.pixelTop=theTop;   c.pixelLeft=theLeft;  }  else if(dom){   c.top=theTop+"px";   c.left=theLeft+"px";  }; }}/*ä¸éŞ snow - End*/window.setInterval("snow()", speed);//ä¸éŞďźsnow

Also you can change the path of the snow image.You can get the image here.
And the code below after <body> tag.



<script type="text/javascript" src="snow.js"></script>

You can get a demo here.


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.