Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fade out a div using jQuery?

Tags:

jquery

Is there any way to fadeout a div after 5 Seconds without using a setTimeOut function?

like image 511
Shiva Srikanth Thummidi Avatar asked Feb 11 '09 12:02

Shiva Srikanth Thummidi


People also ask

How does jQuery fade work?

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.

Which jQuery method is used to fade the controls?

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.


2 Answers

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

like image 166
ExodusNicholas Avatar answered Oct 14 '22 06:10

ExodusNicholas


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) 
like image 32
Ionuț Staicu Avatar answered Oct 14 '22 06:10

Ionuț Staicu