在用jQuery完成淡入淡出效果前我們先來認識幾個代碼:
- 淡入 fadeIn([ speed , [easing] , [fn] ]),引數都可不寫
- 淡出 fadeOut([ speed , [easing] , [fn] ]),引數都可不寫
- 淡入淡出切換 fadeToggle([ speed , [easing] , [fn] ]),引數都可不寫
- 修改透明度 fadeTo([ [speed] , opacity , [easing] , [fn] ]),注意,這里速度和透明度一定要寫
其中
speed是速度
easing是切換效果
fn是回呼函式
那我們把上述代碼放到整體代碼中看下效果

完整代碼如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wellfancy</title>
<style>
div {
margin: 10px;
padding: 10px;
width: 100px;
display: none;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
<button>淡入效果</button>
<button>淡出效果</button>
<button>淡入淡出切換</button>
<button>修改透明度</button>
<div>
<img src="images/1.jpg" style="width: 280px;">
</div>
<script>
$(function() {
$("button").eq(0).click(function() {
$("div").fadeIn(1000);
})
$("button").eq(1).click(function() {
$("div").fadeOut(1000);
})
$("button").eq(2).click(function() {
$("div").fadeToggle(1000);
});
$("button").eq(3).click(function() {
$("div").fadeTo(1000, 0.5);
});
});
</script>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/292518.html
標籤:其他
