Created
May 1, 2014 17:56
-
-
Save DanWebb/11457567 to your computer and use it in GitHub Desktop.
Simple notification object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var notification = { | |
element: $('#notification'), | |
timeout: null, | |
show: function(type, message) { | |
'use strict'; | |
// reset the current timer | |
clearTimeout(this.timeout); | |
this.element | |
// remove any classes already added | |
.removeClass() | |
// set background color | |
.addClass(type) | |
// add message text | |
.html(message) | |
// animate and display | |
.slideDown() | |
// hide notification if clicked | |
.click(function() { | |
notification.hide(); | |
}); | |
// hide automatically after 5 seconds | |
this.timeout = setTimeout(function(){ | |
notification.hide(); | |
},5000); | |
}, | |
hide: function() { | |
'use strict'; | |
// reset the current timer | |
clearTimeout(this.timeout); | |
// animate and hide the notification | |
this.element.slideUp(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment