clearQueue()方法從隊列中刪除所有尚未運行的項目。請注意,一個函數開始運行後,它將一直運行到完成為止。
用法:
$(selector).clearQueue(name);
“selector”是選定的元素。
參數:它接受參數“name”,它是函數的名稱。
返回值:它返回帶有刪除函數的所選元素。
代碼1:
在下麵的代碼中,清除了動畫方法。
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js">
</script>
<script>
<!-- jQuery code to demonstrate clearQueue method -->
$(document).ready(function() {
<!-- click button to start animation -->
$("#b1").click(function() {
$("div").animate({
height: 200
}, 2000);
$("div").animate({
width: 200
}, 2000);
$("div").animate({
height: 100
}, 2000);
$("div").animate({
width: 100
}, 2000);
$("div").animate({
height: 200
}, 2000);
$("div").animate({
width: 200
}, 2000);
$("div").animate({
height: 100
}, 2000);
$("div").animate({
width: 100
}, 2000);
});
<!-- button to stop animation -->
$("#b2").click(function() {
$("div").clearQueue();
});
});
</script>
<style>
div {
background: green;
height: 100px;
width: 100px;
}
button {
margin-top: 10px;
}
</style>
</head>
<body>
<div></div>
<!-- click on this button to start the animation -->
<button id="b1">Start !</button>
<!-- click on this button to stop the animation at
given situation -->
<button id="b2">Stop !</button>
</body>
</html>
輸出:
在單擊任何按鈕之前,
單擊“開始!”後,再經過一段時間“停止!”按鈕,
代碼2:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/
jquery/3.3.1/jquery.min.js"></script>
<script>
<!-- jQuery code to demonstrate clearQueue method -->
$(document).ready(function() {
$(".b1").click(function() {
$("p").animate({
borderRightWidth: "5px"
});
$("p").animate({
borderTopWidth: "5px"
});
$("p").animate({
borderLeftWidth: "5px"
});
$("p").animate({
borderBottomWidth: "5px"
});
});
$(".b2").click(function() {
$("p").clearQueue();
});
});
</script>
<style>
p {
display: block;
width: 150px;
border: 1px solid green;
padding: 10px;
}
</style>
</head>
<body>
<p>This is a paragraph.</p>
<!-- click on this button to start the animation -->
<button class="b1">Start</button>
<!-- click on this button to stop the animation
at given situation -->
<button class="b2">Stop</button>
</body>
</html>
輸出:
在單擊任何按鈕之前,
單擊“開始!”後,再經過一段時間“停止!”按鈕,
相關用法
- JQuery val()用法及代碼示例
- JQuery last()用法及代碼示例
- JQuery has()用法及代碼示例
- JQuery first()用法及代碼示例
- JQuery after()用法及代碼示例
- JQuery eq()用法及代碼示例
- JQuery on()用法及代碼示例
- JQuery one()用法及代碼示例
- JQuery size()用法及代碼示例
- JQuery serializeArray()用法及代碼示例
- JQuery slice()用法及代碼示例
- JQuery mousemove()用法及代碼示例
- JQuery slideUp()用法及代碼示例
- JQuery prop()用法及代碼示例
- JQuery removeProp()用法及代碼示例
注:本文由純淨天空篩選整理自kundankumarjha大神的英文原創作品 jQuery | clearQueue() with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。