I am creating a slideshow using a javascript. I have created a loop that is responsible for changing the css of my slideshow. I want this loop to be endless since I want to change the slides after every set interval.
However, the endless loop is causing my whole website to hang and crash. I want to know if there is an alternative approach to this that doesn't cause my whole page to crash?
async function startSlideShow(slideshow, leftPos, timer) {
let slideContainer = slideshow.children[0];
//How to handle this
let index = 0;
do {
if (index === (leftPos.length - 1)) {
index = 0;
} else {
changeSlide(index);
index++;
}
} while (true);
function changeSlide(index){
setTimeout(function(){
slideContainer.style.left = "-" + leftPos[index] + "px";
console.log("-" + leftPos[index] + "px");
}, timer * index)
}
}