1-1jQuery Fading 方法
1-1-1jQuery fadeIn() 方法(用于淡入已隐藏的元素。)
语法
$(selector).fadeIn(speed,callback);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="jquery/jquery-3.6.0.js"></script>
<style>
button{
background-color: #eee;
color: cyan;
}
div{
width: 80px;
height: 80px;
display: none;
}
.div1{
background-color: cyan;
}
.div2{
background-color: darkgoldenrod;
}
.div3{
background-color: darkred;
}
</style>
</head>
<body>
<p>演示带有不同参数的 fadeIn() 方法。</p>
<button>点击这里,使三个矩形淡入</button>
<br>
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<script>
$(document).ready(function(){
$("button").click(function(){
$(".div1").fadeIn();
$(".div2").fadeIn("slow");----速度
$(".div3").fadeIn(3000);
})
})
</script>
</body>
</html>
1-1-2 jQuery fadeOut() 方法(用于淡出可见元素)
语法
$(selector).fadeOut(speed,callback);
<script>
$(document).ready(function(){
$("button").click(function(){
$(".div1").fadeOut();
$(".div2").fadeOut("slow");
$(".div3").fadeOut(3000);
})
})
</script>
1-1-3 jQuery fadeToggle() 方法(可以在 fadeIn() 与 fadeOut() 方法之间进行切换)
语法
$(selector).fadeToggle(speed,callback);
<script>
$(document).ready(function(){
$("button").click(function(){
$(".div1").fadeToggle();
$(".div2").fadeToggle("slow");
$(".div3").fadeToggle(3000);
})
})
</script>
1-1-4 jQuery fadeTo() 方法(允许渐变为给定的不透明度(值介于 0 与 1 之间))
语法
$(selector).fadeTo(speed,opacity,callback);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="jquery/jquery-3.6.0.js"></script>
<style>
button{
background-color: #eee;
color: cyan;
}
div{
width: 80px;
height: 80px;
}
.div1{
background-color: red;
}
.div2{
background-color: green;
}
.div3{
background-color: blue;
}
</style>
</head>
<body>
<p>演示带有不同参数的 fadeTo() 方法。</p>
<button>点击这里,使三个矩形淡出</button>
<br>
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<script>
$(document).ready(function(){
$("button").click(function(){
$(".div1").fadeTo("slow",0.15);
$(".div2").fadeTo("slow",0.4);
$(".div3").fadeTo("slow",0.7);
})
})
</script>
</body>
</html>