0
I have a challenge that I need the Divs to appear in sequence, one after the other.
To do this, I created a loop that performs the functions of FadeIn() and FadeOut() for each DIV element of my HTML.
However, as I understand it, the loop is running everything at once, without having an interval between the appearance of a div and another. I tried using functions like setInteval() and sleep(), but I was unsuccessful.
Follows code
            $(document).ready(function() {
                var tempo = 2000;
                var quant = $("#conteudos").children().length;
                var res = tempo * quant;
            
                carregar();
                
                function carregar(){
                    var i = [1,2,3,4,5];
                    var quanti = i.length;
                    
                     for(j=0;j<quanti;j++){
                        var divagora = i[j];    
                        $("#div"+divagora).fadeIn();
                        $("#div"+divagora).fadeOut(3000);
                    
                     }
                
                }
        });<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
    <head>
        
    </head>
<body>
    <div id="conteudos">
        <div id="div1" style="position:absolute; display: none; width: 100px; height: 100px; background-color: red"></div>
        <div id="div2" style="position:absolute; display: none; width: 100px; height: 100px; background-color: blue"></div>
         <div id="div3" style="position:absolute; display: none; width: 100px; height: 100px; background-color: black"></div>
        <div id="div4" style="position:absolute; display: none; width: 100px; height: 100px; background-color: yellow"></div>
        <div id="div5" style="position:absolute; display: none; width: 100px; height: 100px; background-color: purple"></div>
    </div>
</body>
</html>Would anyone have any proposal for this case ?
Thank you!
It has to be with JS, it looks pretty simple to do with CSS...
– hugocsl
@hugocsl it is necessary to use JS because in the Array I will determine which Divs will participate in the loop.
– Vinicius