Image cycling

  • intrepid design
  • Student
  • Student
  • User avatar
  • Posts: 91
  • Loc: Chicago

Post 3+ Months Ago

Dose anyone know the java script code that allows you to cycle to a new image every time the page is refreshed? Some one told me it was a simple seed command. what I'm trying to do it to have the main image on the splash page of my website change every time a person refreshes or comes back to the page. Any suggestions?




http://www.danwulfing.com
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

I don't know if this is the best way, but you can do it like this. Replace the img tag with this below, changing the image names of course:

Code: [ Select ]
<script>
var imageFolder = "";        //Change this to the relative path if images in a different folder
                            //make sure you include the "/" at the end of the path.
                            
var imageList = new Array('Image1.jpg','Image2.jpg','Image3.jpg');    //keep adding image names here

//do not edit below:
var whichImage = imageList[parseInt(Math.random()*(imageList.length))];    
document.writeln("<img src='"+imageFolder+whichImage+"' alt='splash image' />");
</script>
  1. <script>
  2. var imageFolder = "";        //Change this to the relative path if images in a different folder
  3.                             //make sure you include the "/" at the end of the path.
  4.                             
  5. var imageList = new Array('Image1.jpg','Image2.jpg','Image3.jpg');    //keep adding image names here
  6. //do not edit below:
  7. var whichImage = imageList[parseInt(Math.random()*(imageList.length))];    
  8. document.writeln("<img src='"+imageFolder+whichImage+"' alt='splash image' />");
  9. </script>


This will select a random image from the list you supply. Add a path where it says if the images are in a different folder (leave as blank string if not).

I don't know if there is a better way to do it using javascript but this works for me so....
  • intrepid design
  • Student
  • Student
  • User avatar
  • Posts: 91
  • Loc: Chicago

Post 3+ Months Ago

thanks for your help, i appreciate it very much.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 75 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.