Cycling through images on a timer

S

Sha Crawford

I have a series of images called shacam1, shacam2..... shacam(n) I
want these to appear on my blog as if they were a feed from a webcam. I
need a little piece of code to select a random image to start from and
to then cycle through the images in order, refreshing every 5000ms.
Help?
 
E

Evertjan.

Sha Crawford wrote on 09 nov 2005 in comp.lang.javascript:
I have a series of images called shacam1, shacam2..... shacam(n) I
want these to appear on my blog as if they were a feed from a webcam. I
need a little piece of code to select a random image to start from and
to then cycle through the images in order, refreshing every 5000ms.

Sure, show us your code, and where you go wrong.

Programme it for you?

No, not me, you'll have to pay someone
or find a kind soul on the way,
or search Google.
 
D

David Wahler

Sha said:
I have a series of images called shacam1, shacam2..... shacam(n) I
want these to appear on my blog as if they were a feed from a webcam. I
need a little piece of code to select a random image to start from and
to then cycle through the images in order, refreshing every 5000ms.
Help?

I'll give you a few hints.

When the page is loaded, you want to:

* Load the list of images
* Pick a random offset
* Load the next image. This task consists of:
* Setting your <img> element's src attribute
* Advancing the offset into the list by 1, resetting it to the
beginning if it's at the end of the list
* Setting a timer to load the next image 5 seconds later

If I'm understanding your question correctly, that's almost a
line-for-line translation of the JavaScript for achieving what you
want. Now go do some research and implement it yourself. The
setTimeout() and Math.random() functions and the % operator will be
particularly useful.

-- David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top