I am making an image carousel using setInterval and if statements and the images display fine however when the carousel starts again an icon that is usually displayed when the page can't find your image is displayed.
<img src="images/img1.jpg" id="images">
<script>
var start = 1;
var timer = setInterval(carousel, 1000);
function carousel(){
var image_data;
if (start==1) {
image_data="images/img1.jpg";
}else if (start==2) {
image_data="images/img2.jpg";
}else if (start==3) {
image_data="images/img3.jpg";
}else if (start==4) {
image_data="images/img4.jpg";
}else if (start==5) {
image_data="images/img5.jpg";
}else {
start = 0;
}
document.getElementById('images').src=""+ image_data;
start++;
}
</script>
Aucun commentaire:
Enregistrer un commentaire