lundi 3 avril 2017

Set interval random + time out

I am trying to show on my page "wait", then "wait wait", then "wait wait wait" etc. up until ~100 times, and I want that the time between the add of a "wait" is random, so far, I've managed to show up the wait until 100, but I can't add the random of the interval.. (right now I put 10 so that it ends quickly).

I have found those answers on the subjects, but I can't seem to integrate them to my code..

setInterval + Random Number setInterval + Random Number

 var timesRun = 0;
        var t = "wait";
        var interval = setInterval(function(){
            timesRun += 1;
            if(timesRun === 10){
              t = t + "...";
              document.getElementById("sample2-progress").innerHTML = t;
              clearInterval(interval);
            }

            document.getElementById("sample2-progress").innerHTML = t;
             t = t + " wait";
            

        }, 200); 
#preloader  {
     position: fixed;
     top: 0;
     left: 0;
     right: 0;
     bottom: 0;
     background-color: #000;
     z-index: 99999;
    height: 100%;
    overflow: hidden;
 }

#status  {
     width: 100%;
     height: 100%;
     position: absolute;
     left: 0%;
     color: white;
     top: 0%;
     background-repeat: no-repeat;
     background-position: center;
     /*margin: -50% 0 0 -50%;*/
     text-align: center;
 }

 #sample2-log{
        display: none;
 }

 #sample2-progress{
        font-size: 6vh;
top: 2vw;
position: fixed;
text-align: center;
width: 98vw;
left: 2vw;
text-align:left;
 }
<script src="http://ift.tt/1oMJErh"></script>

 <div id="preloader">

    <div id="status">
      <textarea id="sample2-log"></textarea>
      <div id="sample2-progress" class="progress"></div>
    </div>

  </div>



Aucun commentaire:

Enregistrer un commentaire