gpt4 book ai didi

jquery - JQuery中有计时功能吗?

转载 作者:行者123 更新时间:2023-12-01 06:33:17 24 4
gpt4 key购买 nike

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

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

最佳答案

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

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 - JQuery中有计时功能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31205643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com