...

View Full Version : Why does this basic slide show script not work?



sherlockturtle
07-06-2012, 03:12 AM
Why does this basic slide show script not work?


<script type="text/javascript">
var images=new Array(); // slideshow
images[0]="27.jpeg";
images[1]="Capture.png";

function slide(){


for (i=0; i<images.Length; i++)
{
document.getElementById("slide").src = images[i];
}



}
slide();
</script>

DrDOS
07-06-2012, 03:33 AM
Because there is no delay between the images loading into the img tag. You need a setTimeout or setInterval to call the function, can the for loop and have the function self increment when it's called.

Old Pedant
07-06-2012, 03:39 AM
Ummm...because it isn't a slide show?

The net effect of that function is do nothing VISIBLE except simply


document.getElementById("slide").src = "Capture.png";

And even that it will only do if the code appears *AFTER* the <img id="slide"/> in your web page.

You have no delay whatsoever in that code, so it simply runs through the entire image array (however big it is), assigning a new src value to the <img id="slide"/> as fast as it can. Which means that, in the space of no more than a microsecond or two, it has change the src as many times as there are array elements and then quit, leaving, of course, only the very last change (the last element in the array) in place.

So it doesn't even resemble a "slide show". If you don't understand the concepts, maybe you should go find a good one and just use it?

sherlockturtle
07-06-2012, 04:00 AM
I tried this but nothing happens


<script type="text/javascript">
var images=new Array(); // slideshow
images[0]="27.jpeg";
images[1]="Capture.png";

function slide(){


for (i=0; i<images.Length; i++)
{
document.getElementById("slide").src = images[i];
}
}
setInterval("slide();",1000);
</script>

Old Pedant
07-06-2012, 04:10 AM
All that would do is delay all of what I described for 1 second. And then it would still happen the same way.

You clearly don't understand what it takes to make a slide show. Isn't it time to go find a really good one and use it?

sherlockturtle
07-06-2012, 04:23 AM
Tried but was not sure how to implement them.

Philip M
07-06-2012, 07:31 AM
for (i=0; i<images.Length; i++)



Javascript is case-sensitive. Length != length.

There are a zillion slide show scripts out there - Google or search this forum.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum