Queues, queues – who likes queuing, I wonder?
Although not all of us like to queue for things, such as for getting lunch or visiting a bank, queuing is critical to the success of running animations. It matters not one jot if we're using .slideUp()
, .animate()
or even .hide()
– if we chain too many animations, we will hit a point where animations won't run.
To release the animation, we need to explicitly call .dequeue()
, as the methods come in pairs. Consider the following example for a moment, taken from http://cdmckay.org/blog/2010/06/22/how-to-use-custom-jquery-animation-queues/:
Imagine you're making a game and you want to have an object start at top:100px
, then float upwards for 2000 milliseconds. Furthermore, you would like the said object to stay completely opaque for 1000 milliseconds before slowly becoming completely transparent over the remaining 1000 milliseconds:
Time (in ms) |
Top |
Opacity |
---|---|---|
0 |
100px |
1.0 |
500 |
90px |
1.0 |
1000 |
80px |
1.0 |
1500... |