Connecting Tech Pros Worldwide Forums | Help | Site Map

Cycling through images on a timer

Sha Crawford
Guest
 
Posts: n/a
#1: Nov 9 '05
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?


Evertjan.
Guest
 
Posts: n/a
#2: Nov 9 '05

re: Cycling through images on a timer


Sha Crawford wrote on 09 nov 2005 in comp.lang.javascript:[color=blue]
> 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.[/color]
[color=blue]
> Help?[/color]

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.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

David Wahler
Guest
 
Posts: n/a
#3: Nov 9 '05

re: Cycling through images on a timer


Sha Crawford wrote:[color=blue]
> 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?[/color]

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

Closed Thread