I'm trying to create an effect that works in a queue, so that each effect starts only after the previous one finished. I was successful, but I'm sure that there's a cleaner way.
This is what I have so far:
$("tr:last td:nth-child(1) div").slideUp(200, function() {
$("tr:last td:nth-child(2) div").slideUp(200, function() {
$("tr:last td:nth-child(3) div").slideUp(200, function() {
$("tr:last td:nth-child(4) div").slideUp(200, function() {
$("tr:last td:nth-child(5) div").slideUp(200, function() {
$("tr:last td:nth-child(6) div").slideUp(200, function() {
$("tr:last td:nth-child(7) div").slideUp(200, function() {
$("tr:last").remove();
});
});
});
});
});
});
});
There's gotta be a cleaner way, right?
Much obliged in advance.
I'm trying to create an effect that works in a queue, so that each effect starts only after the previous one finished. I was successful, but I'm sure that there's a cleaner way.
This is what I have so far:
$("tr:last td:nth-child(1) div").slideUp(200, function() {
$("tr:last td:nth-child(2) div").slideUp(200, function() {
$("tr:last td:nth-child(3) div").slideUp(200, function() {
$("tr:last td:nth-child(4) div").slideUp(200, function() {
$("tr:last td:nth-child(5) div").slideUp(200, function() {
$("tr:last td:nth-child(6) div").slideUp(200, function() {
$("tr:last td:nth-child(7) div").slideUp(200, function() {
$("tr:last").remove();
});
});
});
});
});
});
});
There's gotta be a cleaner way, right?
Much obliged in advance.
Share Improve this question edited Jan 12, 2011 at 11:59 Cesar 3,5192 gold badges31 silver badges43 bronze badges asked Jan 12, 2011 at 11:57 rpophessagrrpophessagr 8933 gold badges10 silver badges17 bronze badges3 Answers
Reset to default 7Just as you say in your question. Use .queue()
.
http://api.jquery./queue
and check:
What are queues in jQuery?
Ouch, that's horrid! I'd do it by using delay
:
var divs = $("tr:last td div");
divs.each(function(idx, el) {
$(this).delay(idx * 200).slideUp(200, function(){
if (idx === divs.length - 1) { // 0-based index
$("tr:last").remove()
}
});
});
You could make a recursive function:
function slide(i) {
if(i < 8) {
$("tr:last td:nth-child(" + i + ") div").slideUp(200, function() {
slide(i+1);
});
}
else {
$("tr:last").remove();
}
}
slide(1);
But it is all very hardcoded....