I'm facing an issue with two timer bars that each wind down over a 5-second period. When I try to stop and reset the first timer, it simply continues from where it left off instead of resetting.
The desired behavior is as follows:
- Timer1 starts
- User hits key
- Timer1 stops halfway complete
- Timer2 starts
- Timer2 expires
- Timer1 resets to 100% and starts again
This is how Timer1 is started:
function StartTimer1(){
$("#timer-bar").show().width("100%");
$("#timer-bar").hide({
effect: "blind",
easing: "linear",
duration: 5000,
direction: "left",
complete: function () {
//do stuff
}
});
}
When a key is hit, the following code is executed:
//Stop Timer1
$("#timer-bar").stop(true, false);
//Start Timer2
$("#answer-timer-bar").hide({
effect: "blind",
easing: "linear",
duration: 5000,
direction: "left",
complete: function () {
//do stuff
}
});
After Timer2 expires, hitting another key triggers StartTimer1() again. Despite resetting the width to 100% before starting the animation, it simply continues from where it stopped initially. I've experimented with using queues and adding unique queue names to each timer option, but the timer fails to start when queues are specified. I've also tried different options for clearQueue and jumpToEnd parameters with Stop(), without achieving the desired behavior.
Any assistance on this matter would be highly appreciated. Thank you!
JSFiddle: https://jsfiddle.net/58rzg6w0/7