I am really a beginner at javascript and wanted to create a small image slider. I have used setInterval to delay the loading so that it would create a slider effect. But somehow the images are not sliding and I have a hinch that the problem lies in the loop. I have already looked up at some options and am asking here as a last option. Thanks in advance.
<!Doctype html>
<meta charset="UTF-8">
<head>
<title>Simple Image Slider</title>
<script type="text/javascript">
var counter=0;
var images=new Array['download.jpg','images (1).jpg','images.jpg'];
function start(){
setInterval("slide()",2000);
}
function slide(){
for(counter=0;counter<images.length;counter++)
document.getElementById('mageslide').src=images[counter];
}
</script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="wrapper">
<div class="slider" onload="start()">
<img src="images.jpg" id="mageslide"></img>
</div>
**strong text** </div>
</body>
</html>
Your
slide()function is wrong, you’re supposed to iterate one image per interval, not all images in one interval iteration, try this fixed version: