PDA

View Full Version : Snow Script Questions



DJAuto
12-02-2006, 07:29 PM
Hello,

I'm looking a for a script that has falling snow.

However, I would like the snow preferably generated by using the asterisk (*).

If that's not possible it's fine. The one thing I am looking for is that you can configure it to stop at a certain height.

EX - Snow starts from top of page but ends once it reaches a certain height, instead of falling all the way down the page.

12345c
12-03-2006, 02:12 AM
View my script with possibility of images and/or symbols: http://javascript.aho.ru/example/xmp002/falling-snow-en.htm

DJAuto
12-03-2006, 04:08 PM
Is this the proper code?



<script> // CREDITS: checked in IE6,FF1.06,Opera7.54,Opera9.01
// Snowmaker Copyright (c) 2003 Peter Gehrig. All rights reserved.
// Modified (c) 2005, Igor Svetlov, Nickname: 12345c
//Location: http://javascript.aho.ru/example/xmp002/falling-snow.htm
// Permission given to use the script provided that this notice remains as is.
var snowmax=25 // Set the number of snowflakes (more than 30 - 40 not recommended)
var snowcolor=["#c4bbcc","#ccddFF","#ccd6DD"]
// Set the colors for the snow. Add as many colors as you like
var snowtype=["Arial Black","Arial Narrow","Times","Comic Sans MS"]
// Set the fonts, that create the snowflakes. Add as many fonts as you like
var snowletter=["*"];
// Set the letter that creates your snowflake (recommended:*)
var sinkspeed=0.6 // Set the speed of sinking (recommended values range from 0.3 to 2)
var snowmaxsize=45 // Set the maximal-size of your snowflaxes
var snowminsize=18 // Set the minimal-size of your snowflaxes
// Set the snowing-zone
// Set 1 for all-over-snowing, set 2 for left-side-snowing
// Set 3 for center-snowing, set 4 for right-side-snowing
var snowingleft=0.7 //left boundary of snow presence
var snowingwidth=0.3 //width of snow presence in window
var opac=0.35 //snowflakes opacity (0.0-1.0), at 1 it works faster in 2 times
var stepTime=120 //step of time-lapse animation(ms).At less 100 strongly loads processor
var snow=new Array()
var marginbottom
var marginright
var timer
var x_mv=[]; var crds=[]; var lftrght=[];
var browserinfos=navigator.userAgent
d=document
var isOpera=self.opera
var ie5=d.all&&d.getElementById&&!isOpera
var ns6=d.getElementById&&!d.all
var opera9=isOpera&&(document.body.style.opacity=='')
var browserok=ie5||ns6||isOpera
var ww=0;
var timer=0;
d.write('<div id=snowZone style=position:absolute></div>');
var snowmaxOld=0;
function createSnow(){
for(i=0;i<Math.max(snowmax,snowmaxOld);i++){if(i<snowmax){
var o=d.createElement('SPAN');
if(d.getElementById('s'+i)){snowZone.replaceChild(o,d.getElementById('s'+i));}
else{snowZone.appendChild(o);}
o.setAttribute('id','s'+i);
o.style.position='absolute';
o.style.top=0-snowmaxsize;
if(ns6)o.style.MozOpacity=opac;
if(opera9)o.style.opacity=opac;
if(ie5){o.style.filter='alpha';o.filters[0].opacity=opac*100;}
snowZone.childNodes[i].innerHTML=snowletter[Math.floor(snowletter.length*Math.random())];
}else{snowZone.removeChild(d.getElementById('s'+i));}
}snowmaxOld=snowmax;}
function randommaker(range){return Math.floor(range*Math.random())}

function botRight(){ if(ie5||isOpera){marginbottom=d.body.clientHeight; marginright=d.body.clientWidth;
}else if(ns6){marginbottom=innerHeight; marginright=innerWidth;}}
function checkPgDn(){scrltop=ns6?pageYOffset:document.body.scrollTop;}
function snowRestart(s){ if(s)eval(s);
createSnow();
snowsizerange=snowmaxsize-snowminsize;
clearInterval(ww);clearTimeout(timer);
checkPgDn();if(ns6)ww=setInterval(checkPgDn,999);
botRight();
for (i=0;i<snowmax;i++) { crds[i] = 0;
lftrght[i] = Math.random()*20;
x_mv[i] = 0.03 + Math.random()/10;
snow[i]=d.getElementById("s"+i)
snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
snow[i].style.fontSize=snow[i].size=randommaker(snowsizerange)+snowminsize
snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
snow[i].sink=sinkspeed*snow[i].size/5
newPosSnow(randommaker(marginbottom-3*snow[i].size),i);
}if(snowmax)movesnow();else{clearTimeout(timer);clearInterval(ww);}
}
function newPosSnow(y,i){var o;
snow[i].posy=y+(ns6?pageYOffset:d.body.scrollTop);
snow[i].posx=randommaker(marginright*snowingwidth-2*snow[i].size)+marginright*snowingleft
snow[i].size=randommaker(snowsizerange)+snowminsize;
if(snow[i].hasChildNodes()&&(o=snow[i].childNodes[0]).tagName=='IMG')o.width=o.height=randommaker(snowsizerange/1.6)+snowminsize;
if(ie5)snow[i].filters[0].opacity=opac*100;if(ns6||opera9)snow[i].style.opacity=opac;
setTimeout("snow["+i+"].style.visibility='visible';",250);
}
function movesnow() {
for (i=0;i<snowmax;i++) {
snow[i].style.top=snow[i].posy+=snow[i].sink+lftrght[i]*Math.sin(crds[i])/3;
crds[i] += x_mv[i];
snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i]);
var a=marginbottom+scrltop-1.5*snow[i].size-snow[i].posy;
if(a<=9.5*snow[i].size){if(ie5)snow[i].filters[0].opacity=opac*a/(9.5*snow[i].size)*100;
else if(ns6||opera9)snow[i].style.opacity=opac*a/(9.5*snow[i].size);}
if(a<=0 || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){snow[i].style.visibility='hidden';newPosSnow(-1.5*snow[i].size,i);}
}
timer=setTimeout(movesnow,stepTime)
}
/*for (i=0;i<snowmax;i++) {
d.write("<span id='s"+i+"' style='position:absolute;"+(opac<1?"-moz-opacity:"+opac+";filter:alpha(opacity="+(opac*100)+")":"")+";top:-"+snowmaxsize+"'>"
+snowletter[Math.floor(snowletter.length*Math.random())]+"</span>")
}*/
onload=function(){if(browserok)setTimeout(snowRestart,99);}
onmousewheel=onscroll=function(){checkPgDn()}
onresize=function(){botRight();}
</script>


If so, how can I edit it so it starts at the top and stops about half way through? (doesn't fall all the way to the bottom).

Thanks

12345c
12-03-2006, 04:36 PM
Set marginbottom to half of height of window:


function botRight(){ if(ie5||isOpera){marginbottom=d.body.clientHeight/2; marginright=d.body.clientWidth;
}else if(ns6){marginbottom=innerHeight/2; marginright=innerWidth;}}