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.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to fix IE ClearType + jQuery opacity problem i
- void before promise syntax
- jQuery add and remove delay
You can avoid using setTimeout by using the fadeTo() method, and setting a 5 second delay on that.
The 5000 is five seconds in milliseconds.
I use this pause plugin I just wrote
Call it like this :
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.
Previously you would do something like this
The first animate isn't doing anything since you already have opacity 1 on the element, but it would pause for the amount of time.
In jQuery 1.4, they have built this into the framework so you don't have to use the hack like above.
The functionality is the same as the original
jQuery.delay()
plugin http://www.evanbot.com/article/jquery-delay-plugin/4The best way is by using the jQuery delay method:
$('#my_id').delay(2000).fadeOut(2000);
I've written a plugin to let you add a delay into the chain.
for example $('#div').fadeOut().delay(5000).fadeIn(); // fade element out, wait 5 seconds, fade element back in.
It doesn't use any animation hacks or excessive callback chaining, just simple clean short code.
http://blindsignals.com/index.php/2009/07/jquery-delay/