不要弹出,改成冒泡弹窗。 /** * 在网页右下角显示一个气泡提示 * @param {string} message - 提示信息 (支持HTML内容) * @param {number} duration - 提示显示的时长(毫秒),默认为6000ms */ function showNotification(message, duration = 6000) { const notificationDiv = document.createElement('div'); notificationDiv.style.cssText = ` position: fixed; top: 40%; left: 50%; transform: translateX(-50%); background-color: #4CAF50; /* 绿色背景 */ color: white; padding: 15px 20px; border-radius: 5px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 10000; font-size: 16px; opacity: 0; transition: opacity 0.5s ease-in-out; `; notificationDiv.innerHTML = message; // 支持 Html document.body.appendChild(notificationDiv); // 渐入效果 setTimeout(() => { notificationDiv.style.opacity = '1'; }, 10); // 小延迟确保动画生效 // 渐出并移除 setTimeout(() => { notificationDiv.style.opacity = '0'; notificationDiv.addEventListener('transitionend', () => { notificationDiv.remove(); }, { once: true }); }, duration); } 类似效果
提个小建议,alert改成mscAlert,复用论坛的提醒UI
@酒神 #11

已更新,提示复用论坛UI
不要弹出,改成冒泡弹窗。
类似效果
