Jump to content

Random Image Script


Spunky
 Share

Recommended Posts

Hey everyone. I recently made a small change to my website to instead of having a black background it has a nice simple texture background. Certain images I had used I just gave them a black background instead of transparent since you wouldn't see it anyways, but now that I chose to put something other than black there you can see the black behind the images. Changed the issue no problem...except with the images that I have shown randomly using javascript. It won't show the .gif ones at all. I only changed 4 of them to test it so, when you view the site some of them will still show but they still have their black background on them, just refresh the page until you get a .gif image. The images are right below the menu bar; they are actually words in image format.Here is my website. And I will also paste the javascript coding used.

<script type="text/javascript">//<![CDATA[var theImages = [{  url: "http://www.wowtah.com/Images/Tip1.gif"},{  url: "http://www.wowtah.com/Images/Tip2.gif"},{  url: "http://www.wowtah.com/Images/Tip3.gif"},{  url: "http://www.wowtah.com/Images/Tip4.gif"},{  url: "http://www.wowtah.com/Images/Tip5.jpg"},{  url: "http://www.wowtah.com/Images/Tip6.jpg"},{  url: "http://www.wowtah.com/Images/Tip7.jpg"},{  url: "http://www.wowtah.com/Images/Tip8.jpg"},{  url: "http://www.wowtah.com/Images/Tip9.jpg"},{  url: "http://www.wowtah.com/Images/Tip10.jpg"},{  url: "http://www.wowtah.com/Images/Tip11.jpg"}]; var randomNumber;var previouslyUsedRandomNumbers = ""; for(var i = 1; i <= 1; i++){	do	{		randomNumber = Math.floor(Math.random() * theImages.length);	}	while(previouslyUsedRandomNumbers.indexOf("|" + randomNumber + "|") >= 0); 	previouslyUsedRandomNumbers += "|" + randomNumber + "|"; 	document.getElementById("i" + i).src= theImages[randomNumber].url;	}//]]></script>

Also if you could be so kind as to help me figure out why Tip10.jpg does not show up either?? I do not understand why, the image is in the folder just like the rest of them. I was thinking that maybe for some reason this code only worked for a maximum of ten images, but, it does show Tip11.jpg so I don't know.All I want to know is if with this code it is possible to have .gif images appear randomly rather than .jpg images and why Tip10.jpg does no show.Thank you, Spunky.

Link to comment
Share on other sites

  • 4 weeks later...

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
 Share

×
×
  • Create New...