返回值:jQuerystop([clearQueue],[jumpToEnd])
jQuery stop() 方法概述
停止所有在指定元素上正在運(yùn)行的動(dòng)畫。
如果隊(duì)列中有等待執(zhí)行的動(dòng)畫(并且clearQueue沒有設(shè)為true),他們將被馬上執(zhí)行
參數(shù)
[clearQueue],[gotoEnd]Boolean,BooleanV1.2
clearQueue:如果設(shè)置成true,則清空隊(duì)列??梢粤⒓唇Y(jié)束動(dòng)畫。
gotoEnd:讓當(dāng)前正在執(zhí)行的動(dòng)畫立即完成,并且重設(shè)show和hide的原始樣式,調(diào)用回調(diào)函數(shù)等。
[queue],[clearQueue],[jumpToEnd]BooleanV1.7
queue:用來停止動(dòng)畫的隊(duì)列名稱
clearQueue:如果設(shè)置成true,則清空隊(duì)列??梢粤⒓唇Y(jié)束動(dòng)畫。
jumpToEnd:如果設(shè)置成true,則完成隊(duì)列??梢粤⒓赐瓿蓜?dòng)畫。
示例
描述:
停止當(dāng)前正在運(yùn)行的動(dòng)畫:
HTML 代碼:
$("#stop").click(function(){
$("#box").stop();
});
描述:
點(diǎn)擊Go之后開始動(dòng)畫,點(diǎn)Stop之后會(huì)在當(dāng)前位置停下來
HTML 代碼:
<button id="go">Go</button> <button id="stop">STOP!</button>
<div class="block"></div><button id="go">Go</button> <button id="stop">STOP!</button>
<div class="block"></div>
jQuery 代碼:
// 開始動(dòng)畫
$("#go").click(function(){
$(".block").animate({left: '+200px'}, 5000);
});
// 當(dāng)點(diǎn)擊按鈕后停止動(dòng)畫
$("#stop").click(function(){
$(".block").stop();
});