.fadeIn()
.fadeIn( [ duration ], [ callback ] ) 返回: jQuery
描述: 通過淡入的方式顯示匹配元素。
-
version added: 1.0.fadeIn( [ duration ], [ callback ] )
duration一個(gè)字符串或者數(shù)字決定動畫將運(yùn)行多久。
callback在動畫完成時(shí)執(zhí)行的函數(shù)。
-
version added: 1.4.3.fadeIn( [ duration ], [ easing ], [ callback ] )
duration一個(gè)字符串或者數(shù)字決定動畫將運(yùn)行多久。
easing一個(gè)用來表示使用哪個(gè)緩沖函數(shù)來過渡的字符串
callback在動畫完成時(shí)執(zhí)行的函數(shù)。
.fadeIn()方法通過匹配元素的不透明度做動畫效果。
延時(shí)時(shí)間是以毫秒為單位的,數(shù)值越大,動畫越慢,不是越快。字符串 'fast' 和 'slow' 分別代表200和600毫秒的延時(shí)。如果提供任何其他字符串,或者這個(gè)duration參數(shù)被省略,那么默認(rèn)使用400毫秒的延時(shí)
如果提供回調(diào)函數(shù)參數(shù),回調(diào)函數(shù)會在動畫完成的時(shí)候調(diào)用。這個(gè)對于將不同的動畫串聯(lián)在一起按順序排列是非常有用的。這個(gè)回調(diào)函數(shù)不設(shè)置任何參數(shù),但是this是存在動畫的DOM元素,如果多個(gè)元素一起做動畫效果,值得注意的是這個(gè)回調(diào)函數(shù)在每個(gè)匹配元素上執(zhí)行一次,不是這個(gè)動畫作為一個(gè)整體。
我們可以給任何元素做動畫,比如一個(gè)簡單的圖片:
<div id="clickme">
Click here
</div>
<img id="book" src="book.png" alt="" width="100" height="123" />
With the element initially hidden, we can show it slowly:
$('#clickme').click(function() {
$('#book').fadeIn('slow', function() {
// Animation complete
});
});




注意:
-
所有的jQuery效果,包括
.fadeIn(),能使用jQuery.fx.off = true關(guān)閉全局性。更多信息請查看jQuery.fx.off。
Examples:
Example: 一個(gè)一個(gè)的隱藏divs,在600毫秒內(nèi)完成這些動畫。
<!DOCTYPE html>
<html>
<head>
<style>
span { color:red; cursor:pointer; }
div { margin:3px; width:80px; display:none;
height:80px; float:left; }
div#one { background:#f00; }
div#two { background:#0f0; }
div#three { background:#00f; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<span>Click here...</span>
<div id="one"></div>
<div id="two"></div>
<div id="three"></div>
<script>
$(document.body).click(function () {
$("div:hidden:first").fadeIn("slow");
});
</script>
</body>
</html>
Demo:
Example: Fades a red block in over the text. Once the animation is done, it quickly fades in more text on top.
<!DOCTYPE html>
<html>
<head>
<style>
p { position:relative; width:400px; height:90px; }
div { position:absolute; width:400px; height:65px;
font-size:36px; text-align:center;
color:yellow; background:red;
padding-top:25px;
top:0; left:0; display:none; }
span { display:none; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<p>
Let it be known that the party of the first part
and the party of the second part are henceforth
and hereto directed to assess the allegations
for factual correctness... (<a href="#">click!</a>)
<div><span>CENSORED!</span></div>
</p>
<script>
$("a").click(function () {
$("div").fadeIn(3000, function () {
$("span").fadeIn(100);
});
return false;
});
</script>
</body>
</html>