.slideUp()
.slideUp( [ duration ], [ callback ] ) 返回: jQuery
描述: 用滑動動畫隱藏一個匹配元素。
-
version added: 1.0.slideUp( [ duration ], [ callback ] )
duration一個字符串或者數(shù)字決定動畫將運(yùn)行多久。
callback在動畫完成時執(zhí)行的函數(shù)。
-
version added: 1.4.3.slideUp( [ duration ], [ easing ], [ callback ] )
duration一個字符串或者數(shù)字決定動畫將運(yùn)行多久。
easing一個用來表示使用哪個緩沖函數(shù)來過渡的字符串。
callback在動畫完成時執(zhí)行的函數(shù)。
.slideUp()方法將給匹配元素的高度的動畫,這會導(dǎo)致頁面的下面部分滑上去,彌補(bǔ)了顯示物品的方式。一旦高度達(dá)到0,display 樣式屬性將被設(shè)置為none,以確保該元素不再影響頁面布局。
持續(xù)時間是以毫秒為單位的,數(shù)值越大,動畫越慢,不是越快。字符串 'fast' 和 'slow' 分別代表200和600毫秒的延時。如果提供任何其他字符串,或者這個duration參數(shù)被省略,那么默認(rèn)使用400 毫秒的延時。
如果提供回調(diào)函數(shù)參數(shù),回調(diào)函數(shù)會在動畫完成的時候調(diào)用。這個對于將不同的動畫串聯(lián)在一起按順序排列是非常有用的。這個回調(diào)函數(shù)不設(shè)置任何參數(shù),但是this是存在動畫的DOM元素,如果多個元素一起做動畫效果,值得注意的是每執(zhí)行一次回調(diào)匹配的元素,而不是作為一個整體的動畫一次。
我們可以給任何元素做動畫,比如一個簡單的圖片:
<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').slideUp('slow', function() {
// Animation complete.
});
});




注意:
- 所有的jQuery效果,包括
.slideDown(),能使用jQuery.fx.off = true關(guān)閉全局性。更多信息請查看jQuery.fx.off。
例子:
Example: 激發(fā)所有的div中滑動,400毫秒內(nèi)完成的動畫。
<!DOCTYPE html>
<html>
<head>
<style>
div { background:#3d9a44; margin:3px; width:80px;
height:40px; float:left; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
Click me!
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<script>
$(document.body).click(function () {
if ($("div:first").is(":hidden")) {
$("div").show("slow");
} else {
$("div").slideUp();
}
});
</script>
</body>
</html>
Demo:
Example: Animates the parent paragraph to slide up, completing the animation within 200 milliseconds. Once the animation is done, it displays an alert.
<!DOCTYPE html>
<html>
<head>
<style>
div { margin:2px; }
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<div>
<button>Hide One</button>
<input type="text" value="One" />
</div>
<div>
<button>Hide Two</button>
<input type="text" value="Two" />
</div>
<div>
<button>Hide Three</button>
<input type="text" value="Three" />
</div>
<div id="msg"></div>
<script>
$("button").click(function () {
$(this).parent().slideUp("slow", function () {
$("#msg").text($("button", this).text() + " has completed.");
});
});
</script>
</body>
</html>