I understand that you can pass a function to slideUp/slideDown that will run once the transition has completed:
$('li').slideUp({
complete: function(){
alert('done');
}
});
With this HTML an alert is shown 3 times.
<ul>
<li>[content here]</li>
<li>[content here]</li>
<li>[content here]</li>
</ul>
Is there some way to have the complete
function fire only once, when the last list item has completed the slideUp? (fiddle)
You can "redo" your selector and check if this
is the last :
$('li').slideUp({
complete: function(){
if($('li:last').is(this)){
alert('done');
}
}
});
Fiddle : http://jsfiddle.net/5NQsU/
Caching your selector would be even better :
var $li = $('li');
$li.slideUp({
complete: function(){
if($li.last().is(this)){
alert('done');
}
}
});
http://jsfiddle.net/Ultimate/KrW5a/
var total = $('ul').size();
var i = 1;
$('li').slideUp({
complete: function () {
if (i === total) alert('done');
i += 1;
}
});
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