1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| (function() {
function Toast(container, content, duration) { this.container = document.getElementById(container); this.content = content || "这是一段对话"; this.duration = duration || 2000; }
Toast.prototype.show = function(callback) { this.callback = callback || function() {}; this.container.style.opacity = 1; this.container.style.display = "block"; this.container.innerHTML = this.content;
setTimeout(function() { this.callback && this.callback(); this.hide(); }.bind(this), this.duration);
return this; }
Toast.prototype.hide = function(callback) { this.callback = callback || function() {};
this.container.style.display = "none"; this.callback && this.callback(); return this; }
window.Toast = Toast;
})(window);
|