显示延迟的多个Noty通知

时间:2012-05-30 17:02:57

标签: php jquery mysql notifications

我正在使用noty来显示使用“右上角”警报设置的通知。我对jquery很新,但知道php和mysql足以得到我想做的大部分事情。

我想要做的是使用mySQL获取数据,以查看用户是否需要显示任何通知(已完成)。然后在页面加载时显示通知,我已经完成了,虽然我确定除了重复代码之外还有更优雅的方式来显示多个通知吗?

然后我想为每个通知显示1秒钟的延迟,以便它们不会立即弹出,并且同时消失。我已经研究过.delay()了但是不知道jQuery好一点对我来说没什么用。

我的代码:

$(document).ready(function() {
  var noty_id = noty({"text":"a message","layout":"topRight","type":"inormation","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":1000,"timeout":5000,"closeButton":false,"closeOnSelfClick":true,"closeOnSelfOver":false,"modal":false});
  var noty_id = noty({"text":"a message","layout":"topRight","type":"inormation","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":1000,"timeout":5000,"closeButton":false,"closeOnSelfClick":true,"closeOnSelfOver":false,"modal":false});
});

1 个答案:

答案 0 :(得分:2)

您可以使用setTimeout()本机Javascript函数。这将在给定的超时期限(毫秒)之后排队操作。

$(document).ready(function() {
    var noty_id = noty({"text":"a message","layout":"topRight","type":"inormation","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":1000,"timeout":5000,"closeButton":false,"closeOnSelfClick":true,"closeOnSelfOver":false,"modal":false});
    setTimeout(function() {   var noty_id = noty({"text":"a message","layout":"topRight","type":"inormation","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":1000,"timeout":5000,"closeButton":false,"closeOnSelfClick":true,"closeOnSelfOver":false,"modal":false}); }, 5000)
});

您可以找到jQuery Pines更好的通知系统,用于排队多个通知。