I view only the first image. I checked every word but I don't find the error. This is the code:
www.jsfiddle.net/4kgg5teg/
Thank you, and sorry for bad english.
I view only the first image. I checked every word but I don't find the error. This is the code:
www.jsfiddle.net/4kgg5teg/
Thank you, and sorry for bad english.
Here you go
http://jsfiddle.net/4kgg5teg/1/
It was the setTimeout
you need to pass in the function, not a string of the name. Also the function was nested in the for loop which it didn't need to be.
I went ahead and simplified your code considerably. There were numerous problems with it, such as your nesting and passing a string to
setTimeout
.HTML
The only change there was making the name attribute into an id. This is a choice of preference; I think it makes the code more readable and reliable. (Instead of
document.images.slide
we can now dodocument.getElementById("slide")
in our JavaScript code.JavaScript
As you can see, my code is considerably shorter. The two main changes I made was cutting out the
img
array (which was plain confusing) and usingsetInterval
instead ofsetTimeout
to avoid recursion. Additionally I fixed the references to your images tolist/[img #].jpg
fromimg[img #].src
(I got that path from your HTML). Another minor change I made was using the remainder operator (%) (also known as modulo operator) instead of the if/else to makestep
"wraparound."I hope that my revisions solved your problem and more importantly helped you realize how to solve issues like this one in the future.
Best of luck,
pzp