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




注意:
-
所有的jQuery效果,包括
.fadeOut(),能使用jQuery.fx.off = true關(guān)閉全局性。更多信息請(qǐng)查看jQuery.fx.off。
Examples:
Example: 淡出所有段落,在600毫秒內(nèi)完成這些動(dòng)畫。
<!DOCTYPE html>
<html>
<head>
<style>
p { font-size:150%; cursor:pointer; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<p>
If you click on this paragraph
you'll see it just fade away.
</p>
<script>
$("p").click(function () {
$("p").fadeOut("slow");
});
</script>
</body>
</html>
Demo:
Example: 點(diǎn)擊淡出在span,
<!DOCTYPE html>
<html>
<head>
<style>
span { cursor:pointer; }
span.hilite { background:yellow; }
div { display:inline; color:red; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<h3>Find the modifiers - <div></div></h3>
<p>
If you <span>really</span> want to go outside
<span>in the cold</span> then make sure to wear
your <span>warm</span> jacket given to you by
your <span>favorite</span> teacher.
</p>
<script>
$("span").click(function () {
$(this).fadeOut(1000, function () {
$("div").text("'" + $(this).text() + "' has faded!");
$(this).remove();
});
});
$("span").hover(function () {
$(this).addClass("hilite");
}, function () {
$(this).removeClass("hilite");
});
</script>
</body>
</html>