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.
Javascript Queue is one of the linear data structures used to store data in the memory. The queue is a linear data structure that stores data sequentially based on the First In First Out (FIFO) manner and is also known as the First Come First Served data structure. The queue has two ends, namely- rear and front.
Queues can be implemented in JavaScript using either the push and shift methods or unshift and pop methods of the array object.
Stacks and Queues are always the most discussed data structures. This is because they both have opposite operations. Stack follows the pattern LIFO — Last In First Out whereas Queues uses FIFO — First In First Out. A common example of a Stack is a pile of plates while that of Queue is a queue at a bus station.
A queue data structure has two fundamental operations: enqueue—This operation is responsible for inserting or pushing a new element to the queue. dequeue—This operation is responsible for removing the oldest element from the queue.
Just as you say in your question. Use .queue()
.
http://api.jquery.com/queue
and check:
What are queues in jQuery?
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