在jQuery1.4中性增加的,
.delay()
方法允许我们将队列中的函数延时执行。它既可以推迟动画队列中函数的执行,也可以用于自定义队列。只有队列中连续的事件会延迟; 例如,不带参数的
.show()
或者
.hide()
不
会延迟,因为他们没有使用效果队列
延时时间(duration参数)是以毫秒为单位的,数值越大,动画越慢,不是越快。字符串
'fast'
和
'slow'
分别代表200和600毫秒的延时。
使用标准效果列队,举个例子,我们可以在
<div id="foo">
的
.slideUp()
和
.fadeIn()
动画之间设置800毫秒的延时:
div { position: absolute; width: 60px; height: 60px; float: left; }
.first { background-color: #3f3; left: 0;}
.second { background-color: #33f; left: 80px;}
<script src="https://code.jquery.com/jquery-latest.js"></script>
<p><button>Run</button></p>
<div class="first"></div>
<div class="second"></div>
$("button").click(function() {
$("div.first").slideUp(300).delay(800).fadeIn(400);
$("div.second").slideUp(300).fadeIn(400);