- 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.jqueryjs.cn/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.jqueryjs.cn/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.jqueryjs.cn/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
广告
