使用 .stop(true, true) 去掉占位符 (.stop( [clearQueue ] [, jumpToEnd ] ))。 jumpToEnd 会隐藏,所以再显示一遍,timer2结束后回调:
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); 并在蓝条完成后重置样式 (.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>