jQueryの停止アニメーション
jQuery stop() メソッド
jQuery stop() メソッドは、アニメーションやエフェクトを完了前に停止するために使用されます。
stop() メソッドは、スライド、フェード、カスタム アニメーションを含むすべての jQuery エフェクト関數(shù)で動作します。
構(gòu)文:
$(selector).stop(stopAll,goToEnd);
オプションの stopAll パラメーターは、アニメーション キューをクリアするかどうかを指定します。デフォルトは false で、アクティブなアニメーションのみを停止し、キューに入れられたアニメーションを逆方向に実行できます。
オプションの goToEnd パラメーターは、現(xiàn)在のアニメーションをすぐに完了するかどうかを指定します。デフォルトは false です。
そのため、デフォルトでは、stop() は選択した要素に指定されている現(xiàn)在のアニメーションをクリアします。
次の例は、パラメータなしの stop() メソッドを示しています:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("#div1").click(function(){ $("#div2").slideDown(5000); }); $("#stop").click(function(){ $("#div2").stop(); }); }); </script> <style type="text/css"> #div2,#div1 { padding:5px; text-align:center; background-color:#e5eecc; border:solid 1px #c3c3c3; } #div2 { padding:50px; display:none; } </style> </head> <body> <button id="stop">停止滑動</button> <div id="div1">點我向下滑動面板</div> <div id="div2">我們必須接受失望,因為它是有限的,但千萬不可失去希望,因為它是無窮的</div> </body> </html>
プログラムを?qū)g行して試してください
jQuery stop() アニメーション (パラメータ付き)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("#start").click(function(){ $("div").animate({left:'100px'},5000); $("div").animate({fontSize:'3em'},5000); }); $("#stop").click(function(){ $("div").stop(); }); $("#stop2").click(function(){ $("div").stop(true); }); $("#stop3").click(function(){ $("div").stop(true,true); }); }); </script> </head> <body> <button id="start">開始</button> <button id="stop">停止</button> <button id="stop2">停止所有</button> <button id="stop3">停止動畫,但完成動作</button> <p>點擊 "開始" 按鈕開始動畫。</p> <p>點擊 "停止" 按鈕停止當(dāng)前激活的動畫,但之后我們能再動畫隊列中再次激活。</p> <p>點擊 "停止所有" 按鈕停止當(dāng)前動畫,并清除動畫隊列,所以元素的所有動畫都會停止。</p> <p>點擊 "停止動畫,但完成動作" 快速完成動作,并停止它。</p> <div style="background:#98bf21;height:100px;width:200px;position:absolute;">HELLO</div> </body> </html>
プログラムを?qū)g行して試してください