0
非常に完璧に機能するちょっとしたコードを準備しました - テキストを空の文字列に設定するときに一時停止を避けたい場合を除いて( "hello world"と "こんにちは宇宙 ")。テキストが設定されていないときに遅延を上げる
どのようにすればいいですか?認めなければならない - 私はしませんでした... :-(
<!-- 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;
}
いいえ、*に*メッセージを設定する必要があります。つまり、あなたのユーザにメッセージを表示したくない場合は、メッセージボックスが ''に設定されている(そしてその後、実際にはこれに含まれていない他のコードが実行されている) hello world demo)、次の*メッセージ*が表示される前に一時停止を削除するには? – Hein
あなたは空白のボックスを表示したいのですか? – wesbos
番号なし。私はちょうど正しい方向に私を指摘しましたが、何らかの理由でここで彼の答えを削除したShanw Chinのおかげで答えが見つかりました。残念ながら私は自分の質問に最も早く7時間で答えることができるので、今ここで解決策を投稿することはできません...とにかくお返事に感謝します – Hein