4

我正在使用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});
});
4

1 回答 1

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是一个更好的通知系统,可以将多个通知排队。

于 2012-05-30T17:16:34.703 回答