jQuery中淡入動(dòng)畫fadeIn
fadeOut是淡出效果,相反的還有淡入效果fadeIn,方法使用上兩者都是一致的,只是結(jié)果相反
.fadeIn( [duration ], [ complete ] )
- duration:指定過渡動(dòng)畫運(yùn)行多長(zhǎng)時(shí)間(毫秒數(shù)),默認(rèn)值為400。該參數(shù)也可以為字符串"fast"(=200)或"slow"(=600)。
- 元素顯示完畢后需要執(zhí)行的函數(shù)。函數(shù)內(nèi)的this指向當(dāng)前DOM元素。
fadeIn()函數(shù)用于顯示所有匹配的元素,并帶有淡入的過渡動(dòng)畫效果。
注意:
- 淡入的動(dòng)畫原理:操作元素的不透明度從0%逐漸增加到100%
- 如果元素本身是可見的,不對(duì)其作任何改變。如果元素是隱藏的,則使其可見
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<style>
select{
width:100%;
height: 30px;
}
p {
color: red;
display: none;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
<h2>fadeIn</h2>
<p>測(cè)試文字淡出效果</p>
<p>慕課網(wǎng),專注分享</p>
選擇:淡出的隱藏效果
</br>
</br>
<select id="animation">
<option value="1">fadeIn( )</option>
<option value="2">fadeIn( "slow" )</option>
<option value="3">fadeIn( 3000 )</option>
<option value="4">fadeIn( 2000, complete )</option>
<option value="5">fadeIn( 1000, "linear" )</option>
<option value="6">fadeIn( options )</option>
</select>
</br></br>
<input id="btnFadeIn" type="button" value="執(zhí)行淡出效果" />
<input id="btnHide" type="button" value="點(diǎn)擊隱藏" />
<script type="text/javascript">
//【顯示】按鈕
$("#btnFadeIn").click(function() {
var v = $("#animation").val();
if (v == "1") {
$("p").fadeIn();
} else if (v == "2") {
$("p").fadeIn("slow");
} else if (v == "3") {
$("p").fadeIn(3000);
} else if (v == "4") {
$("p").fadeIn(2000, function() {
alert("顯示完畢!");
});
} else if (v == "5") {
$("p").fadeIn(1000, "linear");
} else if (v == "6") {
$("p").fadeIn({
duration: 1000
});
}
});
// 【隱藏】按鈕
$("#btnHide").click(function() {
$("p").hide();
});
</script>
</body>
</html>
請(qǐng)驗(yàn)證,完成請(qǐng)求
由于請(qǐng)求次數(shù)過多,請(qǐng)先驗(yàn)證,完成再次請(qǐng)求