2012-07-17 49 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 
        } 
       });