Javascript noty Jquery插件超时未发生
当输入消息列表时,Jquery noty插件超时不起作用。我从servlet获取消息列表,然后像这样调用notyJavascript noty Jquery插件超时未发生,javascript,jquery,jquery-plugins,notifications,noty,Javascript,Jquery,Jquery Plugins,Notifications,Noty,当输入消息列表时,Jquery noty插件超时不起作用。我从servlet获取消息列表,然后像这样调用noty <script> function callNotification() { <c:foreach var = "message" items = "${sessionScope.notification}"> notify('${message}'); </c:foreach&g
<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>
函数callNotification()
{
通知('${message}');
}
功能通知(消息)
{
诺蒂({
“文本”:消息,
“主题”:noty_theme_facebook”,
“布局”:右上角,
“信息”,“动画打开”:{“高度”:“切换”},
“信息”,“动画打开”:{“高度”:“切换”},
“速度”:500,
“超时”:5000,
“closeButton”:正确,
“closeOnSelfClick”:true,
“closeOnSelfOver”:false,
“模态”:假
})
理想情况下,这应该循环消息并以5000ms的超时时间打印它们。但是这会一次打印所有消息。我进一步尝试使用javascript本机setTimeout函数,并用它替换我的callNotification
function callNotification()
{
<c:foreach var = "message" items = "${sessionScope.notification}">
(function(message){
setTimeout(function(){notify('${message}');},5000)
}('${message}')
}}
</c:foreach>
}
函数callNotification()
{
(功能(信息){
setTimeout(函数(){notify('${message}');},5000)
}(“${message}”)
}}
}
但这也被证明是无效的。奇怪的是,当我替换
“布局时,超时似乎工作正常“:在notify方法中居中。我哪里出错了。我希望消息显示的时间不超过5秒,在这5秒后,第一条消息将自动删除,下一条消息将显示。为了使此工作正常,我在jquery.noty.js中更改了以下内容
self.$bar.delay(self.options.timeout).promise().done(function () {
self.close();
});
对此
setTimeout(function () {
self.close();
}, self.options.timeout);
Noty的编码是这样的,如果你的Noty中有按钮,它会禁用超时。这对我来说没有意义,但事实就是这样
这就是罪魁祸首(第62行):
只需删除this.options.timeout=false;
,如果您有一个带按钮的Noty,这将保持超时工作。您需要将此选项作为参数提供:
“按钮:false”您也可以通过在初始化期间指定此选项来实现此目的
buttons: false
更多信息,请在jquery.noty.packaged.js中创建一个名为“master_self”的全局变量。现在在第103或104行中必须有一行
var self=this;
就在该行下方,将master\u self分配为selfmaster\u 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);
我的答案是v2.3.7
Noty返回一个javascript对象,因此如果您通过console.dir(n)在firebug上检查它,您将找到返回对象的所有方法和属性
以下将设置3秒超时:
var n = noty({text: 'noty - a jquery notification library!'});
n.setTimeout(3000);
尝试closeWith
with timeout选项,希望它能正常工作
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
}
});
你有没有想过这个问题?你使用的是promise.js文件吗?你有没有尝试过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
}
});