I want to let an element fade in, and stay on the page for 7 seconds before it fades out. And I can cancel it anytime.
I defined the following functions. But when I called info_timeout.setup(ele, 'some msg here')
, the ele just faded in and faded out immediately.
Am I missing something?
var info_timeout = {
show_info: function(){
this.ele.html(this.msg).fadeIn('normal');
this.id = setTimeout(this.hide_info(), 7000);
},
hide_info: function(){
console.log(this.ele, this.id);
this.ele.fadeOut('slow');
delete this.id;
},
setup: function(ele, msg) {
this.ele = ele;
this.msg = msg;
this.cancel();
this.show_info();
},
cancel: function() {
if(typeof this.timeoutID == "number") {
clearTimeout(this.id);
delete this.id;
}
}
};
Thanks.