- jQuery 教程
- jQuery - 首頁
- jQuery - 路線圖
- jQuery - 概述
- jQuery - 基礎
- jQuery - 語法
- jQuery - 選擇器
- jQuery - 事件
- jQuery - 屬性
- jQuery - AJAX
- jQuery DOM 操作
- jQuery - DOM
- jQuery - 新增元素
- jQuery - 刪除元素
- jQuery - 替換元素
- jQuery CSS 操作
- jQuery - CSS 類
- jQuery - 尺寸
- jQuery - CSS 屬性
- jQuery 效果
- jQuery - 效果
- jQuery - 動畫
- jQuery - 鏈式操作
- jQuery - 回撥函式
- jQuery 遍歷
- jQuery - 遍歷
- jQuery - 遍歷祖先節點
- jQuery - 遍歷子孫節點
- jQuery UI
- jQuery - 互動
- jQuery - 小部件
- jQuery - 主題
- jQuery 參考
- jQuery - 選擇器
- jQuery - 事件
- jQuery - 效果
- jQuery - HTML/CSS
- jQuery - 遍歷
- jQuery - 其他
- jQuery - 屬性
- jQuery - 工具函式
- jQuery 外掛
- jQuery - 外掛
- jQuery - PagePiling.js
- jQuery - Flickerplate.js
- jQuery - Multiscroll.js
- jQuery - Slidebar.js
- jQuery - Rowgrid.js
- jQuery - Alertify.js
- jQuery - Progressbar.js
- jQuery - Slideshow.js
- jQuery - Drawsvg.js
- jQuery - Tagsort.js
- jQuery - LogosDistort.js
- jQuery - Filer.js
- jQuery - Whatsnearby.js
- jQuery - Checkout.js
- jQuery - Blockrain.js
- jQuery - Producttour.js
- jQuery - Megadropdown.js
- jQuery - Weather.js
- jQuery 有用資源
- jQuery - 問答
- jQuery - 快速指南
- jQuery - 有用資源
- jQuery - 討論
jQuery 停止() 方法
jQuery 中的stop()方法用於停止選定元素上當前正在執行的動畫。
此方法停止選定元素上的動畫,它可以清除動畫佇列,防止任何排隊的動畫執行。根據傳遞的引數,可以選擇跳到動畫的末尾。
語法
以下是 jQuery 中 stop() 方法的語法:
$(selector).stop(stopAll,goToEnd)
引數
此方法接受以下可選引數:
stopAll (可選): 一個布林值,指示是否停止選定元素上的排隊動畫。預設為"false"。
goToEnd (可選): 一個布林值,指示是否透過跳轉到末尾立即完成當前動畫。預設為"false"。
示例 1
以下示例演示如何使用 stop() 方法停止當前正在執行的動畫:
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("#startBtn").click(function(){
$("div").animate({height: 200}, 2000);
$("div").animate({width: 200}, 2000);
});
$("#stopBtn").click(function(){
$("div").stop();
});
});
</script>
</head>
<body>
<button id="startBtn">Start</button>
<button id="stopBtn">Stop</button>
<div style="background:#40a944; height:100px; width:100px"></div>
</body>
</html>
動畫佇列中有兩個動畫。當我們點選“開始”按鈕時,佇列中的第一個動畫(高度)將開始,如果我們點選“停止”按鈕,第一個正在執行的動畫將停止,第二個動畫將立即開始。
示例 2
以下示例演示如何使用 stop() 方法停止排隊的動畫。為此,我們需要像下面那樣向 stop() 方法提供“stopAll”引數:
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("#startBtn").click(function(){
$("div").animate({height: '400'}, 1000);
$("div").animate({width: '400'}, 1000);
$("div").animate({height: '200'}, 1000);
$("div").animate({width: '200'}, 1000);
});
$("#stopBtn").click(function(){
$("div").stop(true);
});
});
</script>
</head>
<body>
<button id="startBtn">Start</button>
<button id="stopBtn">Stop</button>
<div style="background:#40a944; height:100px; width:100px;"></div>
</body>
</html>
佇列中有 4 個動畫。當我們點選“開始”按鈕時,第一個動畫(高度)將開始,如果我們點選“停止”按鈕,佇列中的下一個動畫將不會開始。
示例 3
以下示例演示如何使用 stop() 方法立即完成所有動畫:
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("#startBtn").click(function(){
$("div").animate({height: '400'}, 1000);
$("div").animate({width: '400'}, 1000);
$("div").animate({height: '200'}, 1000);
$("div").animate({width: '200'}, 1000);
});
$("#stopBtn").click(function(){
$("div").stop(true, true);
});
});
</script>
</head>
<body>
<button id="startBtn">Start</button>
<button id="stopBtn">Stop</button>
<div style="background:#40a944; height:100px; width:100px;"></div>
</body>
</html>
佇列中有 4 個動畫。當我們點選“開始”按鈕時,第一個動畫將開始。如果我們點選“停止”按鈕,第一個動畫將完成並結束。第二個、第三個和第四個動畫也是如此。
jquery_ref_effects.htm
廣告
