.delay()
.delay( duration, [ queueName ] ) 返回: jQuery
描述: 設置一個延時來推遲執(zhí)行隊列中之后的項目。
-
version added: 1.4.delay( duration, [ queueName ] )
duration一個用于設定隊列推遲執(zhí)行的時間,以毫秒為單位的整數。
queueName一個作為隊列名的字符串。默認是動畫隊列
fx。
在jQuery1.4中性增加的,.delay()方法允許我們將隊列中的函數延時執(zhí)行。它既可以推遲動畫隊列中函數的執(zhí)行,也可以用于自定義隊列
延時時間是以毫秒為單位的,數值越大,動畫越慢,不是越快。字符串 'fast' 和 'slow' 分別代表200和600毫秒的延時。
使用標準效果列隊,舉個例子,我們可以設置800毫秒的延時在 <div id="foo"> 的 .slideUp() 和 .fadeIn() 動畫之間:
$('#foo').slideUp(300).delay(800).fadeIn(400);
當這句語句執(zhí)行的時候,這個元素會以300毫秒的卷起動畫,然后在400毫秒淡入動畫前暫停800毫秒。
jQuery.delay() 用來在jQuery動畫效果和類似隊列中是最好的。但不是替代 JavaScript 原生的 setTimeout 函數,后者更適用于通常情況。
Example:
Animate the hiding and showing of two divs, delaying the first before showing it.
<!DOCTYPE html>
<html>
<head>
<style>
div { width: 60px; height: 60px; float: left; }
.first { background-color: #3f3; }
.second { background-color: #33f;}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<p><button>Run</button></p>
<div class="first"></div>
<div class="second"></div>
<script>
$("button").click(function() {
$("div.first").slideUp(300).delay(800).fadeIn(400);
$("div.second").slideUp(300).fadeIn(400);
});
</script>
</body>
</html>