English 中文(简体)
jQuery queue messages
原标题:

I ve got a short function that should show messages on a website.

function showHint() { 
    $( #notify ).html( message text ).show( slide , {direction:  right }, 500);
}

And there is another function that hides the messages.

function hideHint() { 
    $( #notify ).hide( slide , {direction:  right }, 500);
}

The Problem is that if I call this function more than one times it tries to show all messages at the same time and everything breaks. I want to call the function twice and then it should queue the animations and show one message after another. The function should be called more than one times at the same time but shown one after another. The next message should be shown when the firs hides.

How could I solve the Problem? Would be nice!

最佳回答

Here s a mini custom plugin that I ve used in the past that chains a bunch of animations one after another.

// Good for serializing animations
$.fn.chain = function(fn) {
  var elements = this;
  var i = 0;
  function nextAction() {
    if (elements.eq(i)) fn.apply(elements.eq(i), [nextAction]);
    i++;
  }
  nextAction();
};

You might call it like so (Here s an example of it in use):

$(document).ready(function() {
  $( li ).chain(function(nextChain) { this.slideToggle("fast", nextChain); });
});

The function you pass to chain passes another function that you must call when you re down with one cycle. In the example above, we just pass the nextChain function as the callback to the slideToggle.

问题回答

Your showhint function could just start by hiding the notification and when that is complete the callback would be what is the existing showhint function, that would change the text and show it. Code shouldn t be difficult given what you ve already done.

can you not just use a notification plugin? here are two (one, two) that are pretty spiffy.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签