2012-07-17 92 views
7

當消息列表餵了jQuery插件noty超時不工作。我從servlet獲得消息列表,然後像這樣調用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

你有沒有想出解決辦法? – ashes999 2013-06-21 09:58:09

+0

您使用的是promise.js文件嗎? – MaFo 2014-09-04 10:58:47

+0

有沒有試過關閉選項 – 2016-02-24 12:26:03

回答

3

爲了得到這個工作,我改變了jquery.noty.js以下...

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

這個...

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

Noty進行編碼,這樣如果你有按鈕你的Noty,它會禁用超時。這對我來說沒有意義,但事實就是這樣。

這是罪魁禍首(62行):

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

只是刪除this.options.timeout = false;,這將繼續超時工作,如果你有一個按鈕的Noty。

0

您需要提供這個選項作爲參數: 「按鈕:假」

0

在您jquery.noty.packaged.js創建一個名爲「master_self」 file.Now一致的全局變量103或104,必須有 var self = this;只是行下方的行簽署master_self自我master_self = self;

現在創建在同一文件中的函數:

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); 
} 

現在顯式調用此功能上要以這種方式來超時通知只是調用noty對象創建通知後, :

autoTimeout(1000); 
2

我的答案是針對v2.3.7。

Noty返回一個JavaScript對象,因此,如果你這樣做console.dir(N),你會發現返回的對象的所有方法和屬性檢查它的螢火蟲。

下面將集3秒後超時:

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

謝謝,幫了我很多 – Nedudi 2016-06-09 14:05:37

1

嘗試closeWith與超時選項希望它會正常工作

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 
        } 
       });