JS 自定义toast - 使用示例

aa

// 自定义toast - guan - 使用示例:ghToast('提示内容', 2000, function() { /* 回调函数 */ });
function ghToast(msg, duration, callback) {
    duration = isNaN(duration) ? 3000 : duration;
    var m = document.createElement('div');
    m.innerHTML = msg;
    m.style.cssText = "font-size: 14px; background: rgba(0, 0, 0, 0.7); color: #fff; padding: 10px 15px; border-radius: 5px; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 9999;";
    document.body.appendChild(m);
    setTimeout(function() {
        document.body.removeChild(m);
        if (callback) {
            callback();
        }
    }, duration);
}