// baivong.github.io/ function noty(txt, status) { function destroy(time) { $noty.fadeOut((time || 0), function() { $noty.remove(); }); clearTimeout(notyTimeout); } function autoHide() { notyTimeout = setTimeout(function() { destroy(300); }, 2000); } var $wrap = $('<div>', { id: 'baivong_noty_wrap' }), $content = $('<div>', { id: 'baivong_noty_content', 'class': status, html: txt }), $close = $('<div>', { id: 'baivong_noty_close', html: '×' }); if ($noty.length) destroy(); $noty = $wrap.append($content).append($close); $noty.fadeIn(300).appendTo('body'); $noty.click(function() { destroy(); }).hover(function() { clearTimeout(notyTimeout); }, function() { autoHide(); }); autoHide(); } var $noty = []; $('button').click(function() { noty('Dù sao thì nó cũng <strong>đã chạy</strong>', 'success'); });
<button>Noty</button>
#baivong_noty_wrap { display: none; background: #fff; position: fixed; right: 20px; top: 20px; min-width: 150px; max-width: 100%; padding: 15px 25px; border: 1px solid #ddd; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .1), 0 1px 10px rgba(0, 0, 0, .35); cursor: pointer; } #baivong_noty_content { color: #444; } #baivong_noty_content strong { font-weight: bold; } #baivong_noty_content.info strong { color: #2196f3; } #baivong_noty_content.success strong { color: #4caf50; } #baivong_noty_content.error strong { color: #f44336; } #baivong_noty_close { position: absolute; right: 0; top: 0; font-size: 18px; color: #ddd; height: 20px; width: 20px; line-height: 20px; text-align: center; } #baivong_noty_wrap:hover #baivong_noty_close { color: #333; }