user2210516
user2210516

Reputation: 683

Loop my Progress Bar?

I have a problem.

Can someone help to fix this code so that the progressbar starts over again when it reaches 100.

I want that you can see that the work is under progress. With my code now it stops when it reaches 100.

Hope you understand my question.

Another solution could be a progressbar that jumps around on different values the whole time. The only thing thats important is that the progressbar is working all the time until you get redirected from page.

Here is the code for my progressbar at the moment.

$("#progressbar").progressbar();
                var value = 0;
                var timer = setInterval (function ()
                {
                  $("div#progressbar").progressbar ("value", value);
                  value++;
                  if (value > 100) clearInterval (timer);
                }, 200);

Upvotes: 0

Views: 2236

Answers (4)

Samuel Liew
Samuel Liew

Reputation: 79022

Simply set value to 0 when it reaches 100:

if(value > 100) value = 0;

See Live Demo

You do not want to clear the timer as it will stop the animation.

When the page redirects, all timers will be automatically cleared/stopped.

Upvotes: 1

bruhbruh
bruhbruh

Reputation: 311

Your if statement isn't inside a block You should have it like this

if(value > 100){ clearInterval(timer); } 

Also I think the thing you want to reset here is not the interval but the value. So do it like this:

if(value > 100){ value=0; }

That should work

Upvotes: -1

Jai
Jai

Reputation: 74738

You can try with window.clearInterval():

if (value > 100){
  var timer = window.clearInterval(timer);
}

Upvotes: 0

Jayyrus
Jayyrus

Reputation: 13051

what about setting to 0 again progressBar value when it reaches 100?

$("#progressbar").progressbar();
var value = 0;
var timer = setInterval (function (){
$("div#progressbar").progressbar ("value", value);
    value++;
    if (value > 100) value=0;
}, 200);

Upvotes: 2

Related Questions