2011-09-14 14 views
0

非常に完璧に機能するちょっとしたコードを準備しました - テキストを空の文字列に設定するときに一時停止を避けたい場合を除いて( "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; 

    } 

答えて

0

空にするためのテキスト文字列を設定する必要はありません、こんにちは宇宙は単に置き換えますそれは一斉に起こります。休止は ''の全体の回転によって引き起こされます。

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

+0

いいえ、*に*メッセージを設定する必要があります。つまり、あなたのユーザにメッセージを表示したくない場合は、メッセージボックスが ''に設定されている(そしてその後、実際にはこれに含まれていない他のコードが実行されている) hello world demo)、次の*メッセージ*が表示される前に一時停止を削除するには? – Hein

+0

あなたは空白のボックスを表示したいのですか? – wesbos

+0

番号なし。私はちょうど正しい方向に私を指摘しましたが、何らかの理由でここで彼の答えを削除したShanw Chinのおかげで答えが見つかりました。残念ながら私は自分の質問に最も早く7時間で答えることができるので、今ここで解決策を投稿することはできません...とにかくお返事に感謝します – Hein

関連する問題