JQuery中有计时功能吗? [英] Is there a timing function in JQuery?

查看:68
本文介绍了JQuery中有计时功能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以在代码中添加计时器.像执行一个命令,然后3秒后执行另一个命令一样.就像在我的示例中一样,我有两个使用css创建的框.但是我希望第一个盒子立即移动,第二个盒子在几秒钟后移动,这可能吗?如果可以,怎么办?

I'd like to know if i could add timer to my code. Like do a command and then 3 seconds later another command. Like in my example, I have two boxes that i've created using css. But I want the first box to move immediately and the second a few seconds later, is it possible? If so, how?

<script>
jQuery(document).ready(function () {
    jQuery("#firstbox").animate({ top: '500px' }, 'slow');
    jQuery("#secondbox").animate({ top: '500px' }, 'slow');
});
</script>

推荐答案

您可以使用 delay() animate()运行之前设置一些延迟.

You can use delay() to set some delay before animate() run.

设置计时器以延迟队列中后续项目的执行.

Set a timer to delay execution of subsequent items in the queue.

jQuery("#firstbox").animate({
    top: '500px'
}, 'slow');

jQuery("#secondbox").delay(3000).animate({
    top: '500px'
}, 'slow');

这篇关于JQuery中有计时功能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆