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.
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.
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.
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.
The standard way of creating a delay in JavaScript is to use its setTimeout method. For example: console. log("Hello"); setTimeout(() => { console.
setTimeout(function() { $('#foo').fadeOut(); }, 5000);
The 5000 is five seconds in milliseconds.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With