admin管理员组

文章数量:1415120

I want to display little messages to provide feedback to the user while he is providing input or just interacting with the UI.

I need it for my firefox addon, so I have to develop it in plain javascript and not jQuery.

I want the message to appear, but only one message can be visible at the same time, so I need some kind of queue to manage inming messages. After a certain time e.g. 3 sec the message should fade away or just disappear.

For now I am able to add messages to the DOM. Any suggestions how to implement the queue and how to push the messages forward according to the time?

Thanks!

I want to display little messages to provide feedback to the user while he is providing input or just interacting with the UI.

I need it for my firefox addon, so I have to develop it in plain javascript and not jQuery.

I want the message to appear, but only one message can be visible at the same time, so I need some kind of queue to manage inming messages. After a certain time e.g. 3 sec the message should fade away or just disappear.

For now I am able to add messages to the DOM. Any suggestions how to implement the queue and how to push the messages forward according to the time?

Thanks!

Share Improve this question edited Feb 17, 2011 at 11:53 DarkLeafyGreen asked Feb 17, 2011 at 11:10 DarkLeafyGreenDarkLeafyGreen 70.5k136 gold badges392 silver badges616 bronze badges 1
  • Perhaps not call it message queue. Message queuing is terminology reserved for puter science / engineering that describes a different concept. Better call it notification queue. Thanks for updating your question title. – theking2 Commented Aug 3, 2022 at 16:33
Add a ment  | 

3 Answers 3

Reset to default 4

Perheps you need the concept of FIFO (First In First Out)

Take a look at this simple example in plan java script language:

function Queue() {
    var data = [];

    this.isEmpty = function() {
        return (data.length == 0);
    };

    this.enqueue = function(obj) {
        data.push(obj);
    };

    this.dequeue = function() {
        return data.shift();
    };

    this.peek = function() {
        return data[0];
    };

    this.clear = function() {
        data = [];
    };
}

You can use jQuery in a firefox plugin:

Include a script tag in the xul file that points to the jQuery file, e.g.:

<script type="text/javascript" src="chrome://extensionname/content/jquery.js" />

In each js function that uses jQuery, insert this line:

$jQuizzle = jQuery.noConflict(); 

In each jQuery call, if you are trying to manipulate the document in the current browser window, you must supply the context as "window.content.document", like this:

$jQuizzle(".myClass", window.content.document).show();

Then you can use this jQuery plugin: http://benalman./projects/jquery-message-queuing-plugin/

It's not clear what sort of message you want to display. The nsIAlertsService can display messages but I'm not sure how well it queues them. If you want something simpler then perhaps you could just show a custom <tooltip> element.

本文标签: javascriptHow do I create a message queueStack Overflow