Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138134

Alternative method to run the code continuously instead of do-while loops?

$
0
0

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)
    }
}

Viewing all articles
Browse latest Browse all 138134

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>