Reputation: 5921
I generally understand how queue()
and dequeue()
work, but this function looks really encrypted to me:
function displayMessage (msg) {
$('#info').queue(function() {
$(this).fadeTo('slow', 0).queue(function() {
$(this).text(msg).dequeue()
}).fadeTo('slow', 1).dequeue();
})
}
What is really going on here?
Upvotes: 0
Views: 97
Reputation: 95057
.dequeue
simply tells the queue when to continue. this is the old way of doing it, the new way is to accept a parameter to the .queue
callback named next
, then executing that parameter (it's a function) when you want the queue to continue. The old way should still work though. Ref: http://api.jquery.com/queue/
Your code could be simplified to this:
function displayMessage(msg) {
$('#info').fadeTo('slow', 0, function(){
$(this).text(msg).fadeTo('slow',1);
});
}
However i find displaying a message like this to be annoying. I'd suggest speeding up the animation, or possibly removing the animation and instead doing a highlight effect to bring attention to the message.
Note, this will still take into account existing messages that are still fading in and out.
Upvotes: 2