2012-07-17 6 views
7

メッセージのリストを入力すると、Jquery notyプラグインのタイムアウトが機能しません。私はサーブレットからのメッセージのリストを得て、このように呼び出す。noty Jqueryプラグインのタイムアウトが発生していません

<script> 
    function callNotification() 
    { 
     <c:foreach var = "message" items = "${sessionScope.notification}"> 
      notify('${message}'); 
     </c:foreach> 
    } 
    function notify(message) 
    { 
     noty({ 
       "text": message, 
       "theme": noty_theme_facebook", 
       "layout": topRight, 
       "information","animateOpen":{"height":"toggle"}, 
       "information","animateOpen":{"height":"toggle"}, 
       "speed":500, 
       "timeout":5000, 
       "closeButton":true, 
       "closeOnSelfClick":true, 
       "closeOnSelfOver":false, 
       "modal":false 
      }) 
    </script> 

これは、メッセージをループし、5000msのタイムアウトで印刷するのが理想的です。しかし、これは一度にすべてのメッセージを表示します。私はさらにjavascriptのネイティブsetTimeout関数を使用しようとし、私のcallNotificationをこれに置き換えました。

function callNotification() 
    { 
     <c:foreach var = "message" items = "${sessionScope.notification}"> 
     (function(message){ 
      setTimeout(function(){notify('${message}');},5000) 
     }('${message}') 
     }} 
     </c:foreach> 
    } 

しかし、これも無効であることが判明しました。不思議なことに、通知メソッドで"layout":centerを置き換えるとタイムアウトがうまくいくようです。どこが間違っているのですか?私は、最初のメッセージが自動的に消去され、次のメッセージが表示されてから5秒後にメッセージが表示されるようにします。

+0

あなたはこのことを理解しました、それが正常に動作します願っていタイムアウトオプションでcloseWithを試してみてください? – ashes999

+0

promise.jsファイルを使用していますか? – MaFo

+0

あなたはオプション –

答えて

3

は、この作業を取得するために私が...これに

self.$bar.delay(self.options.timeout).promise().done(function() { 
       self.close(); 
      }); 

... jquery.noty.jsに以下の変更

setTimeout(function() { 
       self.close(); 
      }, self.options.timeout); 
8

Notyがコード化されているので、あなたはボタンでを持っている場合あなたのNoty、それはタイムアウトを無効にします。それは私には意味をなさないが、それはそうである。

60: // If we have button disable closeWith & timeout options 
61: this.options.closeWith = []; 
62: this.options.timeout = false; 

だけthis.options.timeout = false;を削除し、ボタン付きNotyを持っている場合には、作業のタイムアウトを維持します:

これは、犯人(ライン62)です。あなたは、パラメータとして、このオプションを提供する必要が

0

: 「ボタン:偽」

0

中にこのオプションを指定することでこれを達成することができますjquery.noty.packaged.jsは "master_self"という名前のグローバル変数を作成します。103行目または104行目には、その行の直下に var self = this;の行がなければなりません。ただ、通知を作成するためのnotyオブジェクトを呼び出した後

function autoTimeout(timeoutVal){ 
    setTimeout(function(){ 
          var self = master_self; 
          if (typeof self.options.animation.close == 'string') { 
           self.$bar.addClass(self.options.animation.close).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() { 
            if(self.options.callback.afterClose) self.options.callback.afterClose.apply(self); 
            console.log(self); 
            self.closeCleanUp(); 
           }); 
          } else { 
           self.$bar.clearQueue().stop().animate(
            self.options.animation.close, 
            self.options.animation.speed, 
            self.options.animation.easing, 
            function() { 
             if(self.options.callback.afterClose) self.options.callback.afterClose.apply(self); 
            }) 
            .promise().done(function() { 
             self.closeCleanUp(); 
            }); 
          } 
         },timeoutVal); 
} 

は今、あなたはこのようにタイムアウトする通知に明示的にこの関数を呼び出す:master_self = self;

は今、同じファイル内の関数を作成する自己としてmaster_selfサイン:

autoTimeout(1000); 
2

私の答えはv2.3.7です。

Notyはjavascriptオブジェクトを返します。したがって、console.dir(n)を実行してFirebugでチェックすると、返されたオブジェクトのすべてのメソッドとプロパティが見つかります。

3秒に設定されます後はタイムアウト:

var n = noty({text: 'noty - a jquery notification library!'}); 
n.setTimeout(3000); 
+0

でお近くにお越しいただき、ありがとうございました。 – Nedudi

1

function generate(type, text) { 

       var n = noty({ 
        text  : text, 
        type  : type, 
        dismissQueue: true, 
        layout  : 'topRight', 
        closeWith : ['click','timeout'], 
        theme  : 'relax', 
        maxVisible : 10, 
        timeout  :7000, 

        animation : { 
         open : 'animated bounceInRight', 
         close : 'animated bounceOutRight', 
         easing: 'swing', 
         speed : 500 
        } 
       }); 
関連する問題