I’m expecting that the 3rd animation is going to be dequeued but it isn’t and I don’t know why. Here’s a demo.
$('#di').animate({left:300},3000,function(){//animation callback
$('#hello').html('1st is done');
}).animate({left:0},3000,function(){//animation callback
$('#hello').html('2nd is done');
}).queue(function(){//queue
$(this).animate({left:300},3000,
function(){//animation callback
$('#hello').html('the inside queue is done');
$(this).dequeue();
})
}).animate({left:0},3000,function(){//animation callback
$('#hello').html('the last queue is done');
});
You need to think in terms of the order in which each function is able to add something to the queue.
Before anything has a chance to animate, the queue will look like this…
Keep in mind that all this occurs before anything has started.
The trouble is that your
dequeueis being added in the callback to an animation that takes place in the yourqueue()callback. This means that new callback gets placed on the end of the queue…So you can see, that you dequeue is stuck on the end, so the queue is stuck after your
queue()callback.