Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait 5 seconds with jQuery?

Tags:

jquery

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.

How can I achieve this?

like image 696
Andrew Avatar asked Dec 02 '09 21:12

Andrew


People also ask

How to set time delay in jQuery?

jQuery delay() Method The delay() method sets a timer to delay the execution of the next item in the queue.

How do you make a delay in JavaScript?

The standard way of creating a delay in JavaScript is to use its setTimeout method. For example: console. log("Hello"); setTimeout(() => { console.


1 Answers

Built in javascript setTimeout.

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

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 introduced the .delay method. Check it out. Note that .delay only works with the jQuery effects queues.

like image 200
Alex Bagnolini Avatar answered Oct 13 '22 00:10

Alex Bagnolini