如何使用jQuery等待5秒钟? [英] How to wait 5 seconds with jQuery?

查看:80
本文介绍了如何使用jQuery等待5秒钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在页面加载时创建一种效果,并在5秒钟后,屏幕上的成功消息消失或向上滑动.

I'm trying to create an effect where the page loads, and after 5 seconds, the success message on the screen fades out, or slides up.

我该如何实现?

推荐答案

内置于javascript setTimeout .

Built in javascript setTimeout.

setTimeout(
  function() 
  {
    //do something special
  }, 5000);

UPDATE :自页面加载完成后,您要等待,因此请将代码放入$(document).ready(...);脚本中.

UPDATE: you want to wait since when the page has finished loading, so put that code inside your $(document).ready(...); script.

UPDATE 2 :jQuery 1.4.0引入了.delay方法. 查看.请注意,.delay仅适用于jQuery效果队列.

UPDATE 2: jquery 1.4.0 introduced the .delay method. Check it out. Note that .delay only works with the jQuery effects queues.

这篇关于如何使用jQuery等待5秒钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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