I am sure I read about this the other day but I can't seem to find where. I have a fadeOut event after which I remove the element and JQuery is removing the elemnt before it has a chance to finish fading out. What is the solution to this again?
+18
A:
You can specify a callback function:
$(selector).fadeOut('slow', function() {
// will be called when the element finishes fading out
// if selector matches multiple elements it will be called once for each
});
Paolo Bergantino
2009-06-30 20:16:31
Paolo, you would have won the Quick-Draw badge ;) http://meta.stackoverflow.com/questions/1289/new-badge-quick-draw
Jonathan Sampson
2009-06-30 20:20:12
Bingo. I thought it was that but what I needed to do was put my entire function in there not just the remove part. P.S. If any one is interested the book I read it in and have now found again is Learning JQuery - Better Interaction and Design. Thanks again
uriDium
2009-06-30 20:23:09
@Jonathan: better make sure that gets implemented retroactively. :) @uriDium: Glad it helped.
Paolo Bergantino
2009-06-30 20:25:33
A:
not working, still plays both animations at the same time.
heres code:
$('a#cl-snp').click(function() {
$('.portItem').fadeOut('400', function() {
$('#snp').fadeIn('400');
return false;
});
});
Luke
2009-09-06 14:49:17
A:
if its something you wish to switch, fading one out and fading another in the same place, you can place a {position:absolute} attribute on the divs, so both the animations play on top of one another, and you don't have to wait for one animation to be over before starting up the next.
Samin
2009-09-17 17:03:44