jQuery Effect show()方法
jQuery中的show()方法是用来显示隐藏和选择的元素。
注意:此方法显示使用CSS display: none属性的隐藏元素。这些元素是不可见的,它们的可见性是隐藏的。
语法:
$(selector).show( speed, easing, callback )
参数:该方法接受上面提到的和下面描述的三个参数。
- speed:这是一个可选参数,用于指定渐变效果的速度。速度的默认值是400毫秒。速度的可能值是。
- milliseconds
- “slow”
- “fast”
- easing。这是一个可选的参数,用于指定元素到不同动画点的速度。缓和的默认值是 “摆动”。缓和的可能值是。
- “swing”
- “linear”
- callback。它是可选参数。回调函数在show()方法完成后执行。
下面的例子说明了jQuery中的show()方法。
例子1:这个例子显示了显示:无的内容和给定的速度。
<!DOCTYPE html>
<html>
<head>
<title>
jQuery Effect show() Method
</title>
<style>
#Outer {
border: 1px solid black;
padding-top: 40px;
height: 140px;
background: green;
display: none;
}
</style>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
</head>
<body style="text-align:center;">
<div id="Outer">
<h1 style="color:white;">
GeeksForGeeks
</h1>
</div><br>
<button id="btn">
Show
</button>
<!-- Script to show display:none content -->
<script>
(document).ready(function () {
("#btn").click(function () {
$("#Outer").show(1000);
});
});
</script>
</body>
</html>
输出:
例子2:这个例子显示了显示:无的内容与摆动缓和值。
<!DOCTYPE html>
<html>
<head>
<title>
jQuery Effect show() Method
</title>
<style>
#Outer {
border: 1px solid black;
padding-top: 40px;
height: 140px;
background: green;
display: none;
}
</style>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
</script>
</head>
<body style="text-align:center;">
<div id="Outer">
<h1 style="color:white;">
GeeksForGeeks
</h1>
</div><br>
<button id="btn">
Show
</button>
<!-- Script to show display: none content
with swing easing -->
<script>
(document).ready(function () {
("#btn").click(function () {
$("#Outer").show("swing");
});
});
</script>
</body>
</html>
输出: