Is there any way to fadeout a div after 5 Seconds without using a setTimeOut function?
The jQuery fadeIn function is just a shortcut to the jQuery animate function. All it does it change the opacity from 0 to 1 over a period of time by incrementing the opacity value.
jQuery fadeToggle() Method The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in. If the elements are faded in, fadeToggle() will fade them out.
everyone knows that in jquery 1.4 there's a delay function now, right?
$('#div').delay(5000).fadeOut(400)
that's how you do it, without having to add any custom functions or plug-ins. it's native to jquery 1.4
Case 1: if you want to start fadeOut after 5 seconds, use this:
jQuery.fn.delay = function(time,func){ return this.each(function(){ setTimeout(func,time); }); };
Then, use it like this:
$('#div').delay(5000, function(){$(#div').fadeOut()})
You can't achieve this without using setTimeOut at all
Case 2: if you want the duration of fadeOut to be 5 seconds, use this:
$('#div').fadeOut(5000)
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