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
CODE
/*下雪snow - Start*/
var no = 10; // number of snows
var speed = 20; // smaller number moves the snows faster
var heart = "images/snow.gif";
var flag = new Array();
var ns4up = (document.layers) ? 1 : 0; // browser sniffer
var ie4up = (document.all) ? 1 : 0;
var dom = (document.getElementById) ? 1 : 0;
// coordinate and position variables
var dx = new Array();
var xp = new Array();
var yp = new Array();
// amplitude and step variables
var 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.
http://www.freewebs.com/yang1984/snow.gif
And the code below after <body> tag.
CODE
<script type="text/javascript" src="snow.js"></script>
You can get a demo here.
http://www.freewebs.com/yang1984/snow.html

