Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

delay JQuery effects

I want to fade out an element and all its child elements after a delay of a few seconds. but I haven't found a way to specify that an effect should start after a specified time delay.

like image 621
Dónal Avatar asked Oct 30 '08 18:10

Dónal


People also ask

Is delay () A event method in jQuery?

The delay() is an inbuilt method in jQuery which is used to set a timer to delay the execution of the next item in the queue.

What is delay () in JavaScript?

Conclusion. setTimeout() is a method that will execute a piece of code after the timer has finished running. let timeoutID = setTimeout(function, delay in milliseconds, argument1, argument2,...); The delay is set in milliseconds and 1,000 milliseconds equals 1 second.

How do you delay a function?

To delay a function call, use setTimeout() function. functionname − The function name for the function to be executed. milliseconds − The number of milliseconds. arg1, arg2, arg3 − These are the arguments passed to the function.

Can you add 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.


2 Answers

setTimeout(function() { $('#foo').fadeOut(); }, 5000); 

The 5000 is five seconds in milliseconds.

like image 94
swilliams Avatar answered Oct 12 '22 15:10

swilliams


I use this pause plugin I just wrote

$.fn.pause = function(duration) {     $(this).animate({ dummy: 1 }, duration);     return this; }; 

Call it like this :

$("#mainImage").pause(5000).fadeOut(); 

Note: you don't need a callback.


Edit: You should now use the jQuery 1.4. built in delay() method. I haven't checked but I assume its more 'clever' than my plugin.

like image 29
Simon_Weaver Avatar answered Oct 12 '22 13:10

Simon_Weaver