Skip to content

Instantly share code, notes, and snippets.

@DanWebb
Created May 1, 2014 17:56
Show Gist options
  • Save DanWebb/11457567 to your computer and use it in GitHub Desktop.
Save DanWebb/11457567 to your computer and use it in GitHub Desktop.
Simple notification object
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