jQuery停止動畫
jQuery停止動畫?
#jQuery stop() 方法用於停止動畫或效果,在它們完成之前。
stop() 方法適用於所有 jQuery 效果函數(shù),包括滑動、淡入淡出和自訂動畫。
?語法:
$(selector).stop(stopAll,goToEnd);
? 可選的 stopAll 參數(shù)規(guī)定是否應(yīng)該清除動畫佇列。預(yù)設(shè)是 false,即僅停止活動的動畫,允許任何排入佇列的動畫向後執(zhí)行。
? 可選的 goToEnd 參數(shù)規(guī)定是否立即完成目前動畫。預(yù)設(shè)是 false。
? 因此,預(yù)設(shè)地,stop() 會清除在被選元素上指定的目前動畫。
下面的範(fàn)例示範(fàn) stop() 方法,不含參數(shù):
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> <script> $(document).ready(function(){ $("#flip").click(function(){ $("#panel").slideDown(5000); }); $("#stop").click(function(){ $("#panel").stop(); }); }); </script> <style type="text/css"> #panel,#flip { padding:5px; text-align:center; background-color:#e5eecc; border:solid 1px #c3c3c3; } #panel { padding:50px; display:none; } </style> </head> <body> <button id="stop">停止滑動</button> <div id="flip">點擊這里,向下滑動面板</div> <div id="panel">Hello world!</div> </body> </html>