Twango Posted October 17, 2011 Report Share Posted October 17, 2011 Hi, I want to make a script that has raining "Leaves" (Or any image...), but randomly it's a Special leave.When you click on that leaf it takes you to a URL. I want it to be like 1 in 100 leaves or so.I can't figure this out;Here's the script I have; I want to modify it to work. <h1>How to play? Look for a special Green leave, then click on it!</h1><!--Copy and Paste into <BODY> Just above the </BODY> tag. --><script type="text/javascript" language="JavaScript1.2"> //Pre-loads your images below//Configure below - change URL path to your imagesgrphcs=new Array(8)Image0=new Image();Image0.src=grphcs[0]="alv.gif";Image1=new Image();Image1.src=grphcs[1]="clv.gif"Image2=new Image();Image2.src=grphcs[2]="dlv.gif"Image3=new Image();Image3.src=grphcs[3]="elv.gif"Image4=new Image();Image4.src=grphcs[4]="oak1.gif"Image5=new Image();Image5.src=grphcs[5]="oak2.gif"Image6=new Image();Image6.src=grphcs[6]="oak4.gif"Image7=new Image();Image7.src=grphcs[7]="oak6.gif"Spec= new Image();Spec.src="specleave.gif"//Smoothness depends on image file size,//the smaller the size the more you can use!// Configure below - change number of images to renderAmount=15;Ypos=new Array();Xpos=new Array();Speed=new Array();Step=new Array();Cstep=new Array();ns=(document.layers)?1:0;ns6=(document.getElementById&&!document.all)?1:0;var Stop = false;if (ns){for (i = 0; i < Amount; i++){var sbsu=Math.floor(Math.random()*2);var P=Math.floor(Math.random()*grphcs.length);rndPic=grphcs[P];document.write("<LAYER NAME='sn"+i+"' LEFT=0 TOP=0><img src="+rndPic+"></LAYER>");}}else{document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">');for (i = 0; i < Amount; i++){var P=Math.floor(Math.random()*grphcs.length);rndPic=grphcs[P];document.write('<img id="si'+i+'" src="'+rndPic+'" style="position:absolute;top:0px;left:0px">');}document.write('</div></div>');}WinHeight=(ns||ns6)?window.innerHeight:window.document.body.clientHeight;WinWidth=(ns||ns6)?window.innerWidth-70:window.document.body.clientWidth;for (i=0; i < Amount; i++){Ypos[i] = Math.round(Math.random()*WinHeight);Xpos[i] = Math.round(Math.random()*WinWidth);Speed[i]= Math.random()*5+3;Cstep[i]=0;Step[i]=Math.random()*0.1+0.05;}function fall(){if (Stop) { clearLeaves(); return; }var WinHeight=(ns||ns6)?window.innerHeight:window.document.body.clientHeight;var WinWidth=(ns||ns6)?window.innerWidth-70:window.document.body.clientWidth;var hscrll=(ns||ns6)?window.pageYOffset:document.body.scrollTop;var wscrll=(ns||ns6)?window.pageXOffset:document.body.scrollLeft;for (i=0; i < Amount; i++){sy = Speed[i]*Math.sin(90*Math.PI/180);sx = Speed[i]*Math.cos(Cstep[i]);Ypos[i]+=sy;Xpos[i]+=sx;if (Ypos[i] > WinHeight){Ypos[i]=-60;Xpos[i]=Math.round(Math.random()*WinWidth);Speed[i]=Math.random()*5+3;}if (ns){document.layers['sn'+i].left=Xpos[i];document.layers['sn'+i].top=Ypos[i]+hscrll;}else if (ns6){document.getElementById("si"+i).style.left=Math.min(WinWidth,Xpos[i]);document.getElementById("si"+i).style.top=Ypos[i]+hscrll;}else{eval("document.all.si"+i).style.left=Xpos[i];eval("document.all.si"+i).style.top=Ypos[i]+hscrll;}Cstep[i]+=Step[i];}setTimeout('fall()',120);}window.onload=fall;// ***** Delay FUNCTION HERE *****setTimeout("Stop=false", 20000); // ***** Delay 1000 = 1 second *****function clearLeaves(){for (i=0; i < Amount; i++){if (ns){document.layers['sn'+i].display='none';}else if (ns6){document.getElementById("si"+i).style.display='none';}else{eval("document.all.si"+i).style.display='none';}}}//--></SCRIPT> 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted October 17, 2011 Report Share Posted October 17, 2011 That's some seriously old code, I don't even remember the last time I saw someone use a layer element. These are the lines where it choose an image: var P=Math.floor(Math.random()*grphcs.length);rndPic=grphcs[P]; You can use Math.random to generate a number between 1 and 100 and check if it's a certain value before either getting a random image like it currently does, or using the other one. Link to comment Share on other sites More sharing options...
Twango Posted October 17, 2011 Author Report Share Posted October 17, 2011 Tried that, didn't work. Link to comment Share on other sites More sharing options...
justsomeguy Posted October 17, 2011 Report Share Posted October 17, 2011 It would work if you do it right. Post your new code if you want help. Link to comment Share on other sites More sharing options...
Twango Posted October 19, 2011 Author Report Share Posted October 19, 2011 I actually removed it, I think I added var scdn=Math.floor(Math.random()*1000);if (scdn == 250){var specleaf = new Image();specleafe.src="SpeacLeaf.gif";rndPic=specleaf;} Link to comment Share on other sites More sharing options...
justsomeguy Posted October 19, 2011 Report Share Posted October 19, 2011 It should only be a filename, not an image object. The else part of that if statement should be the old code that gets a random image from the array. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now