首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >显示具有延迟的多个Noty通知

显示具有延迟的多个Noty通知
EN

Stack Overflow用户
提问于 2012-05-31 01:02:57
回答 1查看 3.5K关注 0票数 4

我正在使用noty来显示使用“右上角”警报设置的通知。我对jquery是个新手,但对php和mysql的了解足以让我完成大部分我想做的事情。

我想做的是使用mySQL获取数据,看看是否需要向用户显示任何通知(完成)。然后在页面加载时显示通知,我也这样做了,尽管我相信有一种更优雅的方式来显示多个通知,而不是重复代码?

然后,我想为每个通知的出现设置一个延迟,比如1秒,这样它们就不会同时出现和消失。我已经研究过.delay(),但是如果对jQuery没有更多的了解,它对我来说几乎毫无用处。

我的代码:

代码语言: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});
  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});
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-31 01:16:35

您可以只使用setTimeout()原生Javascript函数。这将在给定的超时时间(毫秒)后将操作排入队列。

代码语言: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是将多个通知排入队列的更好的通知系统。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10820889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档