I would like to flash a success message on my page.
I am using the jQuery fadeOut
method to fade and then remove the element. I can increase the duration to make it last longer, however this looks strange.
What I would like to happen is have the element be displayed for five seconds, then fade quickly, and finally be removed.
How can you animate this using jQuery?
use
setTimeout(function(){$elem.hide();}, 5000);
Where
$elem
is the element you wish to hide, and5000
is the delay in milliseconds. You can actually use any function within the call tosetTimeout()
, that code just defines a small anonymous function for simplicity.For a pure jQuery approach, you can do
It's a hack, but it does the job