- 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 slideDown() 方法
jQuery 中的 slideDown() 方法用於透過從上到下滑動的動畫來顯示選定的元素。它通常用於在顯示先前隱藏的內容時新增平滑的視覺效果。
注意:此方法適用於使用 jQuery 函式隱藏或具有 CSS 屬性“display:none”的元素,但不適用於使用 visibility:hidden 隱藏的元素。
要向上滑動元素(以隱藏),我們需要使用 slideUp() 方法。
語法
以下是 jQuery 中 slideDown() 方法的語法:
$(selector).slideDown(speed,easing,callback)
引數
此方法接受以下可選引數:
speed (可選):一個字串或數字,用於確定動畫執行的時長。預設值為 400 毫秒。可能的值為:毫秒、slow、fast。
easing (可選):一個字串,指示要用於過渡的緩動函式。預設值為“swing”。可能的值為:swing、linear。
callback (可選):動畫完成後要執行的函式。
示例 1
在以下示例中,我們對 <div> 元素使用 slideDown() 方法:
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn-slide").click(function(){
$("#panel").slideDown();
});
});
</script>
</head>
<body>
<button id="btn-slide">Slide Down</button>
<div id="panel" style="display: none;">
<p>This is some hidden content that will slide down when the button is clicked.</p>
</div>
</body>
</html>
當我們點選“向下滑動”按鈕時,<div> 元素將向下滑動。
示例 2
在此示例中,我們使用持續時間為 1000 毫秒和線性緩動的方式向下滑動 <div> 元素:
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn-slide").click(function(){
$("#panel").slideDown(1000, "linear");
});
});
</script>
</head>
<body>
<button id="btn-slide">Slide Down</button>
<div id="panel" style="display: none;">
<p>This is some hidden content that will slide down with a custom duration and easing.</p>
</div>
</body>
</html>
當我們點選“向下滑動”按鈕時,<div> 元素將在 1 秒的持續時間內向下滑動。
示例 3
在此示例中,我們還將回調函式傳遞給 jQuery slideDown() 方法:
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("#btn-slide").click(function(){
$("#panel").slideDown(500, function(){
alert("Slide down animation completed"); // Alert when slide down animation completes
});
});
});
</script>
</head>
<body>
<button id="btn-slide">Slide Down</button>
<div id="panel" style="display: none;">
<p>This is some hidden content that will slide down. An alert will pop up after the animation completes.</p>
</div>
</body>
</html>
當我們點選按鈕時,<div> 元素將從面板頂部平滑地向下滑動。在向下滑動動畫完成後,將彈出一個帶有“向下滑動動畫完成”訊息的警報。
jquery_ref_effects.htm
廣告
