html5侧边提示框

javascript 复制代码
// 显示通知消息
function showNotification(message, type = 'info') {
	// 创建通知元素
	const notification = document.createElement('div');
	notification.className = `notification notification-${type}`;
	notification.innerHTML = `
        <i class="fas fa-${getNotificationIcon(type)}"></i>
        <span>${message}</span>
    `;

	// 添加样式
	notification.style.cssText = `
        position: fixed;
        top: 90px;
        right: 20px;
        background: ${getNotificationColor(type)};
        color: white;
        padding: 12px 16px;
        border-radius: 6px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        z-index: 3000;
        display: flex;
        align-items: center;
        gap: 8px;
        font-size: 14px;
        max-width: 300px;
        animation: slideInRight 0.3s ease;
        transform: translateX(100%);
    `;

	document.body.appendChild(notification);

	// 显示动画
	setTimeout(() => {
		notification.style.transform = 'translateX(0)';
	}, 10);

	// 自动移除
	setTimeout(() => {
		notification.style.transform = 'translateX(100%)';
		setTimeout(() => {
			if (notification.parentNode) {
				notification.parentNode.removeChild(notification);
			}
		}, 300);
	}, 3000);
}

// 获取通知图标
function getNotificationIcon(type) {
	const icons = {
		success: 'check-circle',
		error: 'exclamation-circle',
		warning: 'exclamation-triangle',
		info: 'info-circle'
	};
	return icons[type] || 'info-circle';
}

// 获取通知颜色
function getNotificationColor(type) {
	const colors = {
		success: '#4CAF50',
		error: '#F44336',
		warning: '#FF9800',
		info: '#2196F3'
	};
	return colors[type] || '#2196F3';
}

以上是提示框的核心代码

提示框的使用如下:

javascript 复制代码
showNotification("数据提交成功!", "success");

showNotification(`数据提交失败!`, "error");

showNotification(`数据提交错误!`, "warning");

以下是警告提示框的效果:

相关推荐
码喽7号17 小时前
vue学习四:Axios网络请求
前端·vue.js·学习
xinzheng新政18 小时前
Javascript 深入学习基础·4
javascript·学习·servlet
粥里有勺糖18 小时前
视野修炼-技术周刊第129期 | 上一次古法编程是什么时候
前端·javascript·github
whuhewei18 小时前
JS获取CSS动画的旋转角度
前端·javascript·css
蓝黑202018 小时前
Vue组件通信之v-model
前端·javascript·vue
像素之间18 小时前
为什么运行时要加set NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve
前端·javascript·vue.js
M ? A18 小时前
Vue转React实战:defineProps精准迁移实战
前端·javascript·vue.js·经验分享·react.js·开源·vureact
西陵19 小时前
别再写 Prompt 了Spec Mode 才是下一代 AI 编程范式
前端·人工智能·ai编程
如意猴19 小时前
【前端】002--怎样制作一个简历界面?
开发语言·前端·javascript
NickJiangDev19 小时前
Elpis Schema 动态组件与表单:配置驱动的完整 CRUD 闭环
前端