当前位置: 首页 > news >正文

html消息提示框封装,默认,失败,警告,成功四个状态

 

 

message.none("请输入用户名");
message.error("请输入搜索内容");
message.info("请输入用户名");
message.success("登录成功");

封装了四种样式 默认成功失败警告 

// 消息提示弹窗
const message = (function () {let zIndex = 999;let marginTop = "26rem";let lastMessage = null; // 存储上一个提示框元素const iconMap = {info: "https://phadwiki-1308066085.file.myqcloud.com/phadcalc/images/info.png",error:"https://phadwiki-1308066085.file.myqcloud.com/phadcalc/images/error.png",success:"https://phadwiki-1308066085.file.myqcloud.com/phadcalc/images/succee.png",};const styleMap = {none: { bgColor: "rgba(0, 0, 0, 0.6)", borderColor: "none", color: "#fff" },info: { bgColor: "#edf2fc", borderColor: "#ebeef5", color: "#909399" },error: { bgColor: "#fef0f0", borderColor: "#fde2e2", color: "#f56c6c" },success: { bgColor: "#f0f9eb", borderColor: "#e1f3d8", color: "#67c23a" },};function clearLastMessage() {if (lastMessage) {lastMessage.classList.add("message-out");setTimeout(() => {lastMessage.remove();lastMessage = null;}, 300);}}function createMessageElement(type, val) {const style = styleMap[type] || styleMap.none;const icon = iconMap[type] || "";const div = document.createElement("div");div.className = "message_list message-in";div.style.cssText = `z-index: ${zIndex++};position: fixed;left: 50%;transform: translateX(-50%);top: ${marginTop};background-color: ${style.bgColor};border: 1px solid ${style.borderColor};padding: 8px;border-radius: 4px;box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);display: flex;align-items: center;pointer-events: auto;transition: opacity 0.3s ease, transform 0.3s ease;`;const img = document.createElement("img");img.src = icon;img.alt = type;img.style.cssText = `width: 16px;height: 16px;margin-right: 8px;display: ${icon ? "inline-block" : "none"};`;const span = document.createElement("span");span.textContent = val;span.style.cssText = `color: ${style.color};font-size: 14px;`;div.appendChild(img);div.appendChild(span);return div;}function showMessage(type, val, time = 1000) {clearLastMessage();const messageEl = createMessageElement(type, val);document.body.appendChild(messageEl);lastMessage = messageEl;setTimeout(() => {messageEl.classList.remove("message-in");messageEl.classList.add("message-out");setTimeout(() => {if (messageEl) {messageEl.remove();if (lastMessage === messageEl) {lastMessage = null;}}}, 300);}, time);return this;}return {none(val, time) {return showMessage.call(this, "none", val, time);},info(val, time) {return showMessage.call(this, "info", val, time);},error(val, time) {return showMessage.call(this, "error", val, time);},success(val, time) {return showMessage.call(this, "success", val, time);},};
})();

http://www.dtcms.com/a/297461.html

相关文章:

  • PPIO上线阿里旗舰推理模型Qwen3-235B-A22B-Thinking-2507
  • CodeSmith从SqlServer生成符合StyleCop规范的实体类
  • AI浪潮涌,数据库“融合智能”奏响产业新乐章
  • 【无标题】qwen3-8b 强化学习训练后的模型,可以接着 进行其他grpo 强化学习训练 吗
  • XCTF-crypto-幂数加密
  • vue3 组件生命周期,watch和computed
  • 腾讯云代码助手使用指南
  • 【调试Bug】网络在训练中输出NaN
  • 工业与安防视频场景下,如何选择更合适的音视频技术方案
  • 创建 GitLab Runner 使用CICD自动化部署容器
  • 2025 Gitee vs. GitLab:全面对比与选择指南
  • MyBatis高级应用实战指南
  • JAVA + 海康威视SDK + FFmpeg+ SRS 实现海康威视摄像头二次开发
  • RWA的法律合规性如何保证?KYC/AML在RWA项目中的作用是什么?
  • 关于回归决策树CART生成算法中的最优化算法详解
  • AWS CAF:企业云转型的战略指南
  • 飞行控制领军者 | 边界智控携高安全级飞控系统亮相2025深圳eVTOL展
  • 多租户系统中的安全隔离机制设计
  • Spring 生态创新应用:现代架构与前沿技术实践
  • 【Rust线程池】如何构建Rust线程池、Rayon线程池用法详细解析
  • SQLFluff
  • 数字增加变化到目标数值动画,js实现
  • react+threejs实现自适应分屏查看/3D场景对比功能/双场景对比查看器
  • GitHub git push 推送大文件
  • Linux: network: wireshark: tcp的segment重组是怎么判断出来的
  • Git下载与安装全攻略
  • reflections:Java非常好用的反射工具包
  • SEC_FirePower 第二天作业
  • 【深度学习新浪潮】Claude code是什么样的一款产品?
  • Keepalived 原理及配置(高可用)