在特定时间后调用函数Jquery?
我正在检查一个js文件表单Bram Jetten:在特定时间后调用函数Jquery?,jquery,function,time,Jquery,Function,Time,我正在检查一个js文件表单Bram Jetten: Notification.fn = Notification.prototype; function Notification(value, type, tag) { this.log(value, type); this.element = $('<li><span class="image '+ type +'"></span>' + value + '</li>'); if(t
Notification.fn = Notification.prototype;
function Notification(value, type, tag) {
this.log(value, type);
this.element = $('<li><span class="image '+ type +'"></span>' + value + '</li>');
if(typeof tag !== "undefined") {
$(this.element).append('<span class="tag">' + tag + '</span>');
}
$("#notifications").append(this.element);
this.show();
}
/**
* Show notification
*/
Notification.fn.show = function() {
$(this.element).slideDown(200);
$(this.element).click(this.hide);
}
/**
* Hide notification
*/
Notification.fn.hide = function() {
$(this).animate({opacity: .01}, 200, function() {
$(this).slideUp(200, function() {
$(this).remove();
});
});
}
...
当我单击该通知时,它也会关闭。但是,如果我在一段时间后不点击它,我希望它自己关闭。如何调用该隐藏函数或在一段时间后当它出现时关闭它?设置超时并强制隐藏
/**
* Show notification
*/
Notification.fn.show = function() {
var self = this;
$(self.element).slideDown(200)
.click(self.hide);
setTimeout(function() {
self.hide();
// 3000 for 3 seconds
}, 3000)
}
换行
Notification.fn.show = function() {
var self=this;
$(this.element).slideDown(200);
$(this.element).click(this.hide);
setTimeout(function(){
self.hide();
},2000);
}
但是您需要一个额外的内部布尔值,这样您就不能两次隐藏(和销毁)通知
Notification.fn.hide = function() {
if (!this.isHidden){
var self=this;
$(this).animate({opacity: .01}, 200, function() {
$(this).slideUp(200, function() {
$(this).remove();
self.isHidden=true;
});
});
}
}
这对我很有效。在一段时间后调用
单击事件
setTimeout(function() { //calls click event after a certain time
$(".signature-container .nf-field-element").append( $('#signature-pad'));
}, 10000);
我使用jQuery1.6.2,它给出了一个错误<代码>如果(!(e=a.ownerDocument.defaultView))返回b代码>作为a.ownerDocument在2秒后未定义
?很抱歉缩小了版本,我会修复它。好吧,因为我不知道代码中出现错误的部分看起来如何,我真的帮不了你。但是我很确定,在hide函数中,您需要说´$(this.element).animate({….})´您在哪里指定ishiden=true?
var that = this;
setTimeout(function() { //calls click event after a certain time
that.element.click();
}, 10000);
setTimeout(function() { //calls click event after a certain time
$(".signature-container .nf-field-element").append( $('#signature-pad'));
}, 10000);