Используйте .stop(true, true)
, чтобы получить оболочку заполнителя (.stop( [clearQueue ] [, jumpToEnd ] )
). jumpToEnd
скроет его, поэтому просто покажите его снова и перезвоните после окончания таймера 2:
function StartTimer1() {
$("#timer1").hide({
effect: "blind",
easing: "linear",
duration: 5000,
direction: "left",
complete: function() {}
});
}
function StopTimer1() {
$("#timer1").stop(true, true).show();
$("#timer2").hide({
effect: "blind",
easing: "linear",
duration: 2000,
direction: "left",
complete: function() {
StartTimer1()
}
});
}
Пример с красной полосой сброса при нажатии кнопки:
function StartTimer1() {
$("#timer1").hide({
effect: "blind",
easing: "linear",
duration: 5000,
direction: "left",
complete: function() {}
});
}
function StopTimer1() {
$("#timer1").stop(true, true).show();
$("#timer2").hide({
effect: "blind",
easing: "linear",
duration: 2000,
direction: "left",
complete: function() {
StartTimer1()
}
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="timer1" style="height:30px; width:100%; background-color:red">
</div>
<div id="timer2" style="height:30px; width:100%; background-color:blue">
</div>
Click First button, then click second, then click first again
<button onclick="StartTimer1();">
Start Timer1
</button>
<button onclick="StopTimer1();">
Stop Timer1 and Start Timer2
</button>
И если вы хотите сбросить красную полосу после завершения анимации синего:
Используйте .stop(true, false);
и сбросьте style (.attr("style"
), когда синяя полоса готова.
function StartTimer1() {
$("#timer1").hide({
effect: "blind",
easing: "linear",
duration: 5000,
direction: "left",
complete: function() {}
});
}
function StopTimer1() {
$("#timer1").stop(true, false);
$("#timer2").hide({
effect: "blind",
easing: "linear",
duration: 2000,
direction: "left",
complete: function() {
$("#timer1").attr("style", "height:30px; width:100%; background-color:red");
StartTimer1();
}
});
}
function StartTimer1() {
$("#timer1").hide({
effect: "blind",
easing: "linear",
duration: 5000,
direction: "left",
complete: function() {}
});
}
function StopTimer1() {
$("#timer1").stop(true, false);
$("#timer2").hide({
effect: "blind",
easing: "linear",
duration: 2000,
direction: "left",
complete: function() {
$("#timer1").attr("style", "height:30px; width:100%; background-color:red");
StartTimer1();
}
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="timer1" style="height:30px; width:100%; background-color:red">
</div>
<div id="timer2" style="height:30px; width:100%; background-color:blue">
</div>
Click First button, then click second, then click first again
<button onclick="StartTimer1();">
Start Timer1
</button>
<button onclick="StopTimer1();">
Stop Timer1 and Start Timer2
</button>