In this code:
$('#bomb').animate({
'top': '+=200px'
}, 3000)
.queue(function() {
$('#explosion').fadeIn();
$(this).dequeue();
});
$('#bomb').fadeOut('fast');
If I replace $(this).dequeue()
with next()
, it appears to do the s开发者_如何学Pythoname thing. What exactly is the difference?
The passing of "next
" to the function was added in 1.4, I think more just as a way to make code more understandable. I think in the case you mentioned you should use next
because it's more readable. There are however situations when you have to use dequeue
.
The fx queue is a special case as it will automatically dequeue
the first element from the queue if it is empty and something is queued. Normally this is not the case.
Consider this:
$("#something").queue("myqueue", function(){/*dostuff*/});
This alone will never execute the function passed. A call to dequeue
is required to start the queue moving:
$("#something").queue("myqueue", function(){/*dostuff*/}).dequeue("myqueue");
精彩评论