【问题标题】:Eleminate the delay when no text is set消除未设置文本时的延迟
【发布时间】:2011-09-14 13:37:13
【问题描述】:

我已经准备了一小段代码,它工作得非常完美 - 除了我想在将文本设置为空字符串(“hello world”和“hello world”之间)时消除暂停。

谁能弄清楚怎么做?必须承认 - 我没有...... :-(

Sandbox is here

    <!-- Put the notificationBar somewhere in your HTML -->
    <div id="notificationBar"></div>

    /* whatever you want it to look like - keep the display: none; */
    #notificationBar {
        display: none;
        padding: 1em;
        border-radius: 5px;
        background-color: red;
        color: white;
    }

jQuery

    // Set it up!
    var notificationTextToggeled = 0; // Always 0
    var notificationDelay = 2000; // Whatever delay you want, in ms (1000 = 1 sec)

    // Here goes your code... intersperse it with notification messages you 
    // want to present to the user... just like below
    notificationToggle ('Hello World');
    notificationToggle ('');
    notificationToggle ('Hello Universe');
    notificationToggle ('Hello Superman');
    notificationToggle (''); 

    // This function will do all the displaying and  will keep an eye 
    // on not waving too many messages to the user in too short time:
    // Each (not empty) message text will be displayed for at least the delay time
    function notificationToggle (text) { 

        var know = $.now(); 

        if (text != $('#notificationBar').html().length && know < (notificationTextToggeled + notificationDelay ))
            $('#notificationBar').delay(notificationDelay, "fx");

        $('#notificationBar').text().length 
            $('#notificationBar').slideUp('slow'); 

         $.queue($("#notificationBar")[0], "fx", function () { 
             $(this).html(text); 
             $.dequeue(this);      
         });

         if (text) 
             $('#notificationBar').slideDown('slow'); 

         notificationTextToggeled = know;   

    }

【问题讨论】:

    标签: jquery notifications queue delay


    【解决方案1】:

    无需将文本字符串设置为空,hello world 只需将其全部替换。暂停是由 '' 的整个旋转引起的

    http://jsfiddle.net/DRLgE/11/

    【讨论】:

    • 不,需要将消息设置为''。也就是说,如果您不想向您的用户显示任何消息......所以,问题仍然是 - 如果消息框设置为 '' (然后正在执行一些其他代码,实际上不在此hello world 演示),如何在显示下一个 message 之前删除暂停...?
    • 没有。无箱。感谢 Shanw Chin,我刚刚找到了答案,他出于某种原因在这里删除了他的答案,尽管它为我指明了正确的方向。不幸的是,我最早可以在 7 小时内自行回答我的问题,所以我现在无法在此处发布解决方案......无论如何,谢谢你的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    相关资源
    最近更新 更多