javascript - Do something after var reaches certain value with setinterval? -


i have bootstrap loading bar updates setinterval every 250ms looks it's making progress. trying show alert , redirect when loading bar reaches 100%.

<div class="progress" style="border-radius:0px;">     <div class="progress-bar progress-bar-success progress-bar-striped active"           style="border-radius:0px;" id="loading" role="progressbar" aria-valuenow="75"           aria-valuemin="0" aria-valuemax="100" style="width: 0%">    </div> </div> 

i've tried adding window.location before end of function not work. how can this? maybe if statement?

        var percentl = 10;         setinterval(function () {             percentl = percentl + 2;             document.getelementbyid("loading").style.width = percentl + "%";         }, 250); 

you can stop timer using clearinterval, add if statement check if % has reached 100 , location.href redirecting url.

var percentl = 10; var timer = setinterval(function () {               percentl = percentl + 2;               document.getelementbyid("loading").style.width = percentl + "%";               if(percentl > 99){                 clearinterval(timer);                 // stuff                 location.href = "redirecttothisurl";               }                           }, 250); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -