Struggling to build my own simple image slider using javascript and it's not cooperating. I need it to cycle through three images. Check out my code:
var counter = 1;
setInterval(function animate() {
var slideshows = document.getElementsByClassName("slide");
for(var i=1; i <slideshows.length+1; i++) {
if(i == counter) {
slideshows[i-1].width = "170px";
} else {
slideshows[i-1].width = "0px"
}
}
if(counter == 3) {
counter = 1;
} else {
counter++;
}
}, 1000);
Here is the corresponding HTML:
<div id="s1" class="slide"></div>
<div id="s2" class="slide"></div>
<div id="s3" class="slide"></div>
The goal is simple: adjust the height of the current slide to 170px, with others set to 0px. However, the first slide remains displayed at all times.