.fadeOut()
.fadeOut( [ duration ], [ callback ] ) 返回: jQuery
描述: 通過淡出的方式顯示匹配元素。
-
version added: 1.0.fadeOut( [ duration ], [ callback ] )
duration一個字符串或者數(shù)字決定動畫將運行多久。
callback在動畫完成時執(zhí)行的函數(shù)。
-
version added: 1.4.3.fadeOut( [ duration ], [ easing ], [ callback ] )
duration一個字符串或者數(shù)字決定動畫將運行多久。
easing一個用來表示使用哪個緩沖函數(shù)來過渡的字符串
callback在動畫完成時執(zhí)行的函數(shù)。
.fadeOut() 方法通過匹配元素的透明度做動畫效果。一旦透明度達到0,display樣式屬性將被設置為none,以確保該元素不再影響頁面布局。
持續(xù)時間是以毫秒為單位的,數(shù)值越大,動畫越慢,不是越快。字符串 'fast' 和 'slow' 分別代表200和600毫秒的延時。如果提供任何其他字符串,或者這個duration參數(shù)被省略,那么默認使用400毫秒的延時。
如果提供回調(diào)函數(shù)參數(shù),回調(diào)函數(shù)會在動畫完成的時候調(diào)用。這個對于將不同的動畫串聯(lián)在一起按順序排列是非常有用的。這個回調(diào)函數(shù)不設置任何參數(shù),但是this是存在動畫的DOM元素,如果多個元素一起做動畫效果,值得注意的是這個回調(diào)函數(shù)在每個匹配元素上執(zhí)行一次,不是這個動畫作為一個整體。
我們可以給任何元素做動畫,比如一個簡單的圖片:
<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)閉全局性。更多信息請查看jQuery.fx.off。
Examples:
Example: 淡出所有段落,在600毫秒內(nèi)完成這些動畫。
<!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: 點擊淡出在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>