Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Effect Queues in Javascript

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.

like image 427
rpophessagr Avatar asked Jan 12 '11 11:01

rpophessagr


People also ask

What is queuing in JavaScript?

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.

Is there queue in JavaScript?

Queues can be implemented in JavaScript using either the push and shift methods or unshift and pop methods of the array object.

What is difference stack and queue in JavaScript?

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.

What is enqueue and dequeue in JavaScript?

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.


1 Answers

Just as you say in your question. Use .queue().

http://api.jquery.com/queue

and check:

What are queues in jQuery?

like image 83
Marnix Avatar answered Nov 04 '22 14:11

Marnix