backdrop-filter下拉出现毛玻璃效果

博客介绍了 CSS 的 backdrop-filter 属性,它能为元素后面区域添加图形效果,如模糊或颜色偏移。要看到效果,元素或其背景需至少部分透明。还对比了 backdrop-filter 与 filter 的区别,并给出实现下拉容器模糊效果的方法及参考链接。

backdrop-filter CSS 属性可以让你为一个元素后面区域添加图形效果(如模糊或颜色偏移)。 因为它适用于元素背后的所有元素,为了看到效果,必须使元素或其背景至少部分透明。
backdrop-filter是让当前元素所在区域后面的内容模糊灰度或高亮之类,要想看到效果,需要元素本身半透明或者完全透明;而filter是让当前元素自身模糊灰度或高亮之类
只要把下拉容器原来的实色background-color变成半透明,再设置一个backdrop-filter blur()模糊就可以了
参考:https://developer.mozilla.org/zh-CN/docs/Web/CSS/backdrop-filter
https://www.zhangxinxu.com/wordpress/2019/11/css-backdrop-filter/

<template> <el-container class="futuristic-layout"> <!-- 左侧侧边栏 --> <el-aside width="240px" class="sidebar"> <!-- Logo 区域 --> <div class="logo-section"> <i class="el-icon-s-grid"></i> <span class="logo-title">管理中心</span> </div> <!-- 主菜单 --> <el-menu :default-active="$route.path" class="glow-menu" background-color="transparent" text-color="#e2e8f0" active-text-color="#60c7ff" unique-opened router > <template v-for="item in menuConfig"> <el-submenu v-if="item.children" :key="item.index" :index="item.index" > <template slot="title"> <i :class="item.icon"></i> <span>{{ item.title }}</span> </template> <el-menu-item v-for="child in item.children" :key="child.index" :index="child.index" > {{ child.title }} </el-menu-item> </el-submenu> <el-menu-item v-else :key="item.index" :index="item.index"> <i :class="item.icon"></i> <span>{{ item.title }}</span> </el-menu-item> </template> </el-menu> </el-aside> <!-- 主内容区域 --> <el-container> <!-- 头部 --> <el-header class="glass-header"> <div class="header-right"> <el-dropdown @command="handleCommand" trigger="click"> <div class="user-badge"> <el-avatar size="small" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" /> <span class="username">管理员</span> <i class="el-icon-arrow-down arrow"></i> </div> <el-dropdown-menu slot="dropdown" class="dropdown-menu"> <el-dropdown-item command="logout" divided> <i class="el-icon-switch-button"></i> 注销登录 </el-dropdown-item> </el-dropdown-menu> </el-dropdown> </div> </el-header> <!-- 主体内容 --> <el-main class="main-view"> <router-view /> </el-main> </el-container> </el-container> </template> <script> export default { name: "AdminLayout", data() { return { menuConfig: [ { index: "0", title: "数据管理", icon: "el-icon-pie-chart", children: [{ index: "/adminChart", title: "数据统计" }], }, { index: "1", title: "信息管理", icon: "el-icon-bell", children: [ { index: "/adminBulletin", title: "公告管理" }, { index: "/adminFeedback", title: "反馈信息" }, ], }, { index: "2", title: "用户管理", icon: "el-icon-user", children: [ { index: "/adminUser", title: "用户信息" }, { index: "/adminCoach", title: "教练信息" }, ], }, { index: "3", title: "课程管理", icon: "el-icon-notebook-2", children: [{ index: "/adminCourse", title: "课程信息" }], }, { index: "4", title: "器材管理", icon: "el-icon-trophy", children: [{ index: "/adminEquipment", title: "器材管理" }], }, { index: "5", title: "预约日志", icon: "el-icon-date", children: [ { index: "/adminCourseAppointment", title: "课程预约" }, { index: "/adminCoachAppointment", title: "教练预约" }, ], }, { index: "6", title: "个人中心", icon: "el-icon-setting", children: [{ index: "/updateAdmin", title: "个人信息" }], }, ], }; }, methods: { handleCommand(command) { if (command === "logout") { this.$message({ type: "success", message: "已成功注销!", duration: 1500, }); this.$router.push("/"); } }, }, }; </script> <style scoped> /* 全局根容器 */ .futuristic-layout { height: 100vh; background: linear-gradient(135deg, #0f172a, #1e293b, #0f172a); font-family: "Segoe UI", "Nunito", "Microsoft YaHei", sans-serif; color: #e2e8f0; overflow: hidden; } /* 侧边栏 - 毛玻璃+深空蓝 */ .sidebar { background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(16px); box-shadow: 2px 0 20px rgba(0, 0, 0, 0.2); border-right: 1px solid rgba(255, 255, 255, 0.08); display: flex; flex-direction: column; transition: width 0.3s ease; } /* Logo 区域 */ .logo-section { height: 70px; display: flex; align-items: center; padding: 0 24px; font-weight: 700; font-size: 1.3rem; color: #ffffff; letter-spacing: -0.5px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); } .logo-section i { margin-right: 12px; font-size: 20px; color: #60c7ff; } .logo-title { background: linear-gradient(to right, #60c7ff, #a4d8ff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; } /* 菜单主体 */ .glow-menu { flex: 1; border-right: none; padding: 20px 0; overflow-y: auto; } /* 菜单项通用样式 */ .glow-menu ::v-deep .el-submenu__title, .glow-menu ::v-deep .el-menu-item { height: 52px; line-height: 52px; padding: 0 24px !important; margin: 6px 12px; border-radius: 14px; color: #e2e8f0 !important; transition: all 0.35s cubic-bezier(0.25, 0.8, 0.25, 1); position: relative; overflow: hidden; } /* 悬停效果:背景光晕扩散 */ .glow-menu ::v-deep .el-submenu__title:hover, .glow-menu ::v-deep .el-menu-item:hover { background: rgba(96, 199, 255, 0.15); color: #60c7ff !important; transform: translateY(-2px); box-shadow: 0 4px 16px rgba(96, 199, 255, 0.1); } /* 激活状态:发光边框 + 高亮背景 */ .glow-menu ::v-deep .el-menu-item.is-active { background: rgba(16, 185, 129, 0.1); color: #60c7ff !important; font-weight: 600; border: 1px solid rgba(96, 199, 255, 0.3); box-shadow: 0 0 20px rgba(96, 199, 255, 0.25); transform: scale(1.02); } /* 图标美化 */ .glow-menu i { margin-right: 12px; width: 20px; text-align: center; color: #94a3b8; transition: color 0.3s ease; } .glow-menu ::v-deep .el-submenu__title:hover i, .glow-menu ::v-deep .el-menu-item:hover i { color: #60c7ff; } /* 头部 - 毛玻璃效果 */ .glass-header { background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(12px); border-bottom: 1px solid rgba(255, 255, 255, 0.15); padding: 0 30px; display: flex; justify-content: flex-end; align-items: center; height: 70px !important; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } .header-right { display: flex; align-items: center; } /* 用户下拉按钮 */ .user-badge { display: flex; align-items: center; gap: 8px; padding: 6px 14px; background: rgba(255, 255, 255, 0.2); border-radius: 20px; cursor: pointer; transition: all 0.3s ease; color: #ffffff; } .user-badge:hover { background: rgba(255, 255, 255, 0.35); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(255, 255, 255, 0.15); } .username { font-weight: 500; font-size: 14px; } .arrow { font-size: 12px; transition: transform 0.3s ease; } .user-badge:hover .arrow { transform: rotate(180deg); } /* 下拉菜单美化 */ .dropdown-menu { border-radius: 16px; overflow: hidden; backdrop-filter: blur(10px); background: rgba(255, 255, 255, 0.95); box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2); padding: 8px 0; } .dropdown-menu ::v-deep .el-dropdown-menu__item { padding: 10px 20px; font-size: 14px; color: #333; transition: background 0.2s; } .dropdown-menu ::v-deep .el-dropdown-menu__item:hover { background: #ecf5ff; color: #409eff; } .dropdown-menu ::v-deep .el-dropdown-menu__item i { margin-right: 8px; color: #409eff; } /* 主内容区 */ .main-view { background: transparent; padding: 28px; min-height: calc(100vh - 70px); color: #e2e8f0; } /* 滚动条美化 */ .sidebar ::v-deep .el-menu { scrollbar-width: thin; scrollbar-color: #60c7ff rgba(15, 23, 42, 0.3); } .sidebar ::v-deep .el-menu::-webkit-scrollbar { width: 6px; } .sidebar ::v-deep .el-menu::-webkit-scrollbar-track { background: rgba(15, 23, 42, 0.3); border-radius: 10px; } .sidebar ::v-deep .el-menu::-webkit-scrollbar-thumb { background: #60c7ff; border-radius: 10px; } .sidebar ::v-deep .el-menu::-webkit-scrollbar-thumb:hover { background: #409eff; } /* 响应式适配 */ @media (max-width: 768px) { .futuristic-layout { flex-direction: column; } .sidebar { width: 100% !important; max-height: 280px; } .glass-header { justify-content: center; } .main-view { padding: 16px; } } </style> 改
09-23
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <meta name="format-detection" content="telephone=no" /> <title>逍遥网络</title> <!-- Favicon --> <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🎮</text></svg>"> <style> /* 重置 */ * { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; background: linear-gradient(45deg, #0f1a2b, #1a2e4d); color: white; min-height: 100vh; padding: 20px 15px 40px; line-height: 1.6; overflow: hidden; } /* 动态星空背景(纯CSS) */ body::before { content: ''; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: radial-gradient(circle at 20% 30%, rgba(60, 100, 255, 0.1) 0%, transparent 30%), radial-gradient(circle at 80% 70%, rgba(255, 100, 150, 0.1) 0%, transparent 30%), radial-gradient(circle at 50% 10%, rgba(100, 200, 255, 0.08) 0%, transparent 25%); z-index: -2; } /* 毛玻璃遮罩层 */ body::after { content: ''; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(10, 20, 40, 0.6); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); z-index: -1; } h2 { text-align: center; color: #00d2ff; font-size: 30px; margin: 30px 0 10px; text-shadow: 0 0 5px rgba(0, 210, 255, 0.5), 0 0 15px rgba(0, 210, 255, 0.3); font-weight: 700; letter-spacing: 1px; animation: glow 2s infinite alternate; } @keyframes glow { from { text-shadow: 0 0 5px rgba(0, 210, 255, 0.5); } to { text-shadow: 0 0 15px rgba(0, 210, 255, 0.8), 0 0 20px rgba(0, 210, 255, 0.4); } } .subtitle { text-align: center; color: #aaa; font-size: 13px; margin-bottom: 30px; opacity: 0.8; } .form { max-width: 400px; margin: auto; background: rgba(30, 50, 80, 0.25); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-radius: 20px; padding: 24px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4), inset 0 0 10px rgba(255, 255, 255, 0.05); border: 1px solid rgba(255, 255, 255, 0.18); position: relative; overflow: hidden; } /* 表单底部微光条 */ .form::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, transparent, #00d2ff, transparent); transform: scaleX(0.5); animation: shine 3s infinite alternate; } @keyframes shine { to { transform: scaleX(1); } } .service-link { display: block; margin: 0 0 16px; padding: 16px; text-decoration: none; border-radius: 14px; font-weight: 600; font-size: 16px; color: white; transition: all 0.3s cubic-bezier(0.2, 0, 0.2, 1); position: relative; overflow: hidden; background: rgba(255, 255, 255, 0.08); border-left: 5px solid transparent; transform: translateZ(0); } /* 根据 data-type 设置专属渐变背景 + 边框光晕 */ .service-link[data-type="local"] { --icon-color: #ff7676; background: linear-gradient(135deg, #1e3c7222, #2a529822); box-shadow: 0 0 6px rgba(255, 150, 150, 0.2); } .service-link[data-type="online-game"] { --icon-color: #64c8ff; background: linear-gradient(135deg, #0f202722, #203a4322, #2c536422); box-shadow: 0 0 6px rgba(100, 200, 255, 0.2); } .service-link[data-type="cdk"] { --icon-color: #ffd966; background: linear-gradient(135deg, #3a7bd522, #3a607322); box-shadow: 0 0 6px rgba(255, 200, 100, 0.2); } .service-link[data-type="test"] { --icon-color: #b066ff; background: linear-gradient(135deg, #5d26c122, #9a00d722); box-shadow: 0 0 6px rgba(180, 100, 255, 0.2); } .service-link[data-type="download"] { --icon-color: #00d2b4; background: linear-gradient(135deg, #00b4db22, #0083b022); box-shadow: 0 0 6px rgba(0, 200, 180, 0.2); } /* 悬停放大 + 阴影加深 + 投影外扩 */ .service-link:hover { transform: translateY(-3px) scale(1.03); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3), 0 0 15px var(--hover-color, rgba(255, 255, 255, 0.3)); } /* 按压反馈 */ .service-link:active { transform: scale(0.98); opacity: 0.8; } /* 自定义图标容器 */ .service-link .icon { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; position: relative; margin-right: 12px; flex-shrink: 0; } /* 圆形背景光晕 */ .service-link .icon::before { content: ''; position: absolute; width: 100%; height: 100%; background: radial-gradient(circle, rgba(255, 255, 255, 0.2) 0%, transparent 70%); border-radius: 50%; z-index: 0; pointer-events: none; } /* 图标文字(使用 Unicode 字符或 SVG) */ .service-link .icon span { font-size: 20px; position: relative; z-index: 1; color: white; text-shadow: 0 0 4px rgba(255, 255, 255, 0.6); } /* 脉冲光圈动画(悬停时出现) */ .service-link .icon::after { content: ''; position: absolute; width: 44px; height: 44px; border: 2px solid var(--icon-color); border-radius: 50%; opacity: 0; transform: scale(0.8); animation: pulse-ring 2s infinite; z-index: -1; pointer-events: none; } @keyframes pulse-ring { 0% { transform: scale(0.8); opacity: 0; } 50% { transform: scale(1.2); opacity: 0.6; } 100% { transform: scale(0.8); opacity: 0; } } /* 默认隐藏脉冲圈,悬停时显示 */ .service-link .icon::after { animation-play-state: paused; } .service-link:hover .icon::after { opacity: 1; animation-play-state: running; } .service-link span.name { vertical-align: middle; } .service-link .status { float: right; font-size: 11px; padding: 3px 8px; border-radius: 10px; background: rgba(0, 0, 0, 0.3); color: #ddd; margin-top: 6px; transition: all 0.3s ease; } .status.online { background: rgba(0, 180, 0, 0.5); color: #fff; box-shadow: 0 0 6px rgba(0, 200, 0, 0.3); } .status.offline { background: rgba(180, 0, 0, 0.5); color: #fff; box-shadow: 0 0 6px rgba(200, 0, 0, 0.3); } .status.loading { background: rgba(100, 100, 100, 0.4); color: #fff; animation: pulse 1.5s infinite; } @keyframes pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } } </style> </head> <body> <h2>✨ 逍遥网络</h2> <p class="subtitle">一站式入口</p> <div class="form"> <a href="" class="service-link" data-port="" data-type="local" target="_blank" rel="noopener noreferrer"> <span class="icon"><span>🔧</span></span> <span class="name">游戏 活动</span> <span class="status loading">检查中...</span> </a> <a href="https://fafa.krific.cn" class="service-link" data-url="https://fafa.krific.cn" data-type="online-game" target="_blank" rel="noopener noreferrer"> <span class="icon"><span>🎮</span></span> <span class="name">游戏 商城</span> <span class="status loading">检查中...</span> </a> <a href="https://sdk.urptwx.cn" class="service-link" data-url="https://sdk.urptwx.cn" data-type="cdk" target="_blank" rel="noopener noreferrer"> <span class="icon"><span>⚙️</span></span> <span class="name">CDK 兑换</span> <span class="status loading">检查中...</span> </a> <a href="" class="service-link" data-port="" data-type="test" target="_blank" rel="noopener noreferrer"> <span class="icon"><span>🧪</span></span> <span class="name">新手 教程</span> <span class="status loading">检查中...</span> </a> <a href="" class="service-link" data-port="" data-type="download" target="_blank" rel="noopener noreferrer"> <span class="icon"><span>📊</span></span> <span class="name">安卓+IOS+PC 游戏下载</span> <span class="status loading">检查中...</span> </a> </div> <script> function checkLocal(port) { return new Promise((resolve) => { const img = new Image(); img.src = `http://127.0.0.1:${port}/favicon.ico?r=${Date.now()}`; img.onload = () => resolve(true); img.onerror = () => resolve(false); setTimeout(() => resolve(false), 3000); }); } async function checkOnline(url) { try { const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 5000); await fetch(url, { method: 'HEAD', mode: 'no-cors', signal: controller.signal }); clearTimeout(timeoutId); return true; } catch (err) { return false; } } document.querySelectorAll('.service-link').forEach(async (link) => { const statusSpan = link.querySelector('.status'); let isOnline = false; if (link.dataset.port) { isOnline = await checkLocal(link.dataset.port); } else if (link.dataset.url) { isOnline = await checkOnline(link.dataset.url); } statusSpan.classList.remove('loading'); statusSpan.textContent = isOnline ? '在线' : '离线'; statusSpan.classList.add(isOnline ? 'online' : 'offline'); }); </script> </body> </html> 在此基础上 不变更现在的显示方案上增加 优化 安卓 IOS PC 检测分辨率自动适配 检测分辨率后 一页显示完整内容 无需下拉 完整写出
10-25
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值