• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 55
  • Last Modified:

JS: image swap on page load

I have a folder full of images (with specific quotes in them) that I would like to randomly swap out on page load.  Not sure the best way to get this done.
0
a204801
Asked:
a204801
  • 2
  • 2
1 Solution
 
Ares KurkluSoftware EngineerCommented:
If the images can have the same name like pic001, pic002 then you can simply generate a random number let's say if you got 100 images , you can generate a number between 1 to 100 and load that image, another way would be somehow to keep a database of the file names or can be hardcoded  array (not ideal)
or read all the image names in the folder order them by name in an array, get the max number of images then randomly pick a number and display that. first option may be the simplest one.

You can do it in JS or in jQuery and display onload.
0
 
a204801Author Commented:
The images are in its own folder and are labeled 001.png, 002.png and so on.  I dont know how to write the code.  How might you conceive it?
0
 
Ares KurkluSoftware EngineerCommented:
There are some good examples in the following links you may follow those:

http://www.dyn-web.com/code/random-image-js/

http://www.mediacollege.com/internet/javascript/image/random.html
0
 
a204801Author Commented:
perfect.  thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now