Queue and dequeue in jquery are a group of useful methods, which are especially useful for a series of functions that require running in order. Special functions such as animate animation, ajax, and timeout are used to display or operate the function queue executed on matching elements in the queue () method.
The process of queue and dequeue is as follows:
Use queue to add functions to the queue (usually a Function Array)
Use dequeue to retrieve the first function in the function array, and execute (use shift () to retrieve and execute)
This means that when dequeue is executed again, another function is obtained. It also means that if dequeue is not executed, the next function in the queue will never be executed.
If you execute the animation Method on an element, jQuery also adds it to the function queue named fx. To execute animations for Multiple Elements in sequence, you must manually set the queue.
In one example, we need to move two p values to the left in sequence:
The Code is as follows:
P 1
P 2