Galen Corey Galen Corey - 6 months ago 53
jQuery Question

Trying to loop through progressbar.js animations

I am trying to countinually alternate between two cycles using progressbar.js. Nothing happens when I run this code, even though it works fine when I am not trying to repeat. Any suggestions?

$(document).ready(function() {

var timer = new ProgressBar.Circle('#progress', {
easing: 'linear',
strokeWidth: 3,
trailWidth: 1,
color: '#ff9900'
});



function loop() {
timer.set(0);
timer.setText('Work');
timer.animate(1, {
duration: 25000
}, function() {
timer.set(0);
timer.setText('Break');
timer.animate(1, {
duration: 5000
},loop);
});

loop();
}

});

Answer
function loop() {
    timer.set(0);
    timer.setText('Work');
    timer.animate(1, {
      duration: 25000
    }, function() {
      timer.set(0);
      timer.setText('Break');
      timer.animate(1, {
        duration: 5000
      },loop);
    });

    loop(); //remove
  }
  loop();//add