With this article I create a simple javascript slideshow. but I can't understand why used from setTimeout on the last of codes. setTimeout just call one times the function .
<html>
<script>
var images = new Array();
images[0] = new Image().src = "1.png";
images[1] = new Image().src = "2.png";
images[2] = new Image().src = "3.png";
images[3] = new Image().src = "4.jpg";
if (!document.images){
console.log("Your Browser Does not support the images class");
}
else {console.log("welcome to your slider")}
</script>
<body>
<img src = "1.png" name = "slide" id="slider" width="300" height="100" />
</body>
<script>
var step = 0
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
{
console.log("your browser doesn't support our site")}
document.getElementById('slider').src = images[step]
if (step<2)
step++
else
step=0
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()",2500)
}
slideit()
</script>
</html>
Thanks