0
shabi posted
how to Change image automatically in every specified seconds by JavaScript
<script>
var image=['image-1.jpg','image-2.jpg','image-3.jpg'];
var i=0;
function AutoChangeImage(){
document.getElementById('image').src=image[i];
i++;
var d;
for(d=0;d<=2000;d++){
//delay
}
AutoChangeImage();
}
</script>
<img src='image.jpg' id="image"/>
if you see above code , i made function AutoChangeImage() to change image but i need it should be change image after 2 second and i used for loop to delay it for 2 second
for(d=0;d<=2000;d++){
//delay
}
i am thinking each iteration take one millisecond .
i do not think its good way to use for loop to delay it .not good at JavaScript so suggest something more better