Communitygithub.com

玻璃态效果(毛玻璃与液态玻璃)

该技能用于创建毛玻璃(毛玻璃效果,Apple液态玻璃风格)UI组件,包括半透明模糊面板、边缘高光、SVG液态折射、悬停/滚动/进入动画,以及无障碍降级方案。

玻璃态效果(毛玻璃与液态玻璃) 是什么?

这个技能专注于在Web界面中实现逼真的玻璃态效果,包括经典的毛玻璃效果和2026年流行的液态玻璃风格。它详细解释了构成真实玻璃感的四个核心要素:模糊与饱和度构成的“霜面”、半透明底色、模拟光线捕捉的明亮边缘高光,以及营造深度感的多层阴影。技能提供了可直接使用的CSS和SVG代码示例,支持悬停、滚动和进入时的动画,从简单的模糊变化到复杂的SVG折射(feDisplacementMap)均涵盖。特别强调了性能优化(如限制模糊半径、避免嵌套backdrop-filter)、跨浏览器兼容性(尤其是Safari的-webkit-前缀)和无障碍设计(prefers-reduced-transparency降级为实心面板,prefers-reduced-motion停止动画)。此外,还包含一个用于冻结动画和状态的测试工具,方便在任意时间点截取确定性画面进行审查。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/nehakanjamala/personal_website/tree/HEAD/.agents/skills/glassmorphism

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

玻璃态效果(毛玻璃与液态玻璃) 是做什么的?

半透明、雾面UI:你可以透过面板看到背景,背景会被模糊成柔和的色块,边缘有一圈明亮的反光,悬浮在层叠的阴影之上。2026年的“液态玻璃”进化增加了折射效果——背景通过面板时会明显弯曲——加上移动的镜面高光。目标是营造深度和材质感,而不仅仅是透明度。

何时使用

  • 在繁忙/有照片的背景上使用毛玻璃卡片、导航栏、侧边栏、模态框/对话框和工具栏
  • 登录/英雄面板和覆盖层,应感觉层叠在页面之上
  • Apple风格的“液态玻璃”英雄区:折射、缓慢翻滚的表面,带有镜面扫描
  • 悬停/滚动/进入动画在玻璃上——霜面加深、高光变亮、面板抬起
  • 任何内容需要呈现为悬浮玻璃,同时保持可读性的地方

逼真玻璃的四个要素

玻璃绝不是一个单一属性。每个面板都需要所有四个要素,否则它看起来就是一个普通的半透明盒子:

  1. 霜面 — backdrop-filter: blur() 加上 saturate() 以保持背景颜色在模糊后依然鲜艳。
  2. 半透明 — 带有alpha通道(~0.08–0.18)的 background,既不完全透明也不完全不透明。
  3. 玻璃边缘 — 比填充色更亮的极细边框,最好是左上角亮 → 右下角暗的高光,让边缘捕捉到光线。
  4. 深度 — 层叠的 box-shadow:一个环境投影让它悬浮,加上一个 inset 顶部高光和底部阴影来让表面有弧度。
.glass {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%); /* Safari 需要前缀 */
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.25),     /* 悬浮 */
    inset 0 1px 0 rgba(255, 255, 255, 0.35), /* 顶部高光 */
    inset 0 -1px 0 rgba(0, 0, 0, 0.12);      /* 底部阴影 */
}

霜面级别:浅色UI镀铬 blur(8–12px) / alpha 0.08–0.14;厚重模态框/登录框 blur(24–40px) / alpha 0.10–0.18。深色玻璃:填充 rgba(0,0,0,0.3),较柔和的顶部高光。

backdrop-filter 只会模糊位于元素后面的内容。 在纯色背景上它不会有可见效果——玻璃需要一个繁忙的背景(图片、渐变、视频)才能产生霜面效果。

镜面边缘高光与抗条带噪点

平面的边框是死板的。通过 ::before 绘制一个带有遮罩的1px发光环(角落高光),并通过 ::after 使用微弱的 feTurbulence 噪点覆盖层(opacity ≤ 0.06)来消除渐变条带(重度模糊下出现的阶梯状轮廓线)。完整的遮罩边框和内联噪点配方在 references/glass-recipes.md 中。

动效:动画化玻璃本身,而非几何形状

动画化玻璃的品质——霜面加深、高光变亮、面板抬起——使其看起来像是表面“倾向光线”。

.glass {
  transition: backdrop-filter .4s ease, background .4s ease,
              box-shadow .4s ease, transform .4s cubic-bezier(.16,1,.3,1);
}
.glass:hover {
  backdrop-filter: blur(24px) saturate(180%);
  background: rgba(255,255,255,.18);
  transform: translateY(-4px);
  box-shadow: 0 16px 48px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.5);
}
  • 进入动效(霜面从清晰逐渐呈现):将 [data-enter] 过渡与 @starting-style { backdrop-filter: blur(0); opacity: 0; transform: translateY(16px) } 配对使用。
  • 镜面扫描:在悬停时或作为缓慢循环的环境光效,在表面上动画化一个倾斜的白色渐变。
  • 注意事项:动画化模糊半径是这里最昂贵的操作——背景每帧都会重新模糊。如果悬停时卡顿,动画化 transform/box-shadow/background(代价低)并保持模糊变化量小或直接切换。

液态玻璃 — SVG 折射(2026年风格)

让背景穿过面板时像厚透镜一样弯曲:使用从动画化的 feTurbulence 驱动 feDisplacementMap,通过 filter 应用(它会扭曲元素自身的像素),并层叠在 backdrop-filter 霜面之上。

<svg width="0" height="0" style="position:absolute"><filter id="liquid-glass">
  <feTurbulence type="fractalNoise" baseFrequency="0.008 0.012" numOctaves="2" seed="3" result="n">
    <animate attributeName="baseFrequency" dur="18s"
             values="0.008 0.012;0.012 0.008;0.008 0.012" repeatCount="indefinite"/>
  </feTurbulence>
  <feDisplacementMap in="SourceGraphic" in2="n" scale="22" xChannelSelector="R" yChannelSelector="G"/>
</filter></svg>

scale = 折射强度(8–14 细微,20–30 明显,>40 熔化)。较低的 baseFrequency = 更大、更慢的波浪(更像液体)。保持 animate 的 dur 较长(12–20s)以使其缓慢呼吸。这些滤镜很消耗性能——仅在一个英雄元素上使用,不要用于网格。

性能 — backdrop-filter 开销很大

  • 每个玻璃元素都会重新采样并模糊其背后的所有内容。限制数量;屏幕上有十几个会严重降低滚动帧率。
  • 将高开销的玻璃提升到单独层(transform: translateZ(0) 或 will-change: transform),并在动画完成后移除 will-change。
  • 不要将 backdrop-filter 元素相互堆叠——嵌套模糊会重新模糊已经模糊的内容(二次成本)。
  • 大半径(>40px)覆盖大面积是最坏情况;限制半径和面板大小。

无障碍 — 不可妥协

玻璃是装饰性的;内容必须保持可读,并且效果必须可以被关闭。

@media (prefers-reduced-transparency: reduce) {
  .glass { background: #1a1a2e; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .glass::after { display: none; }            /* 去掉噪点 */
}
@media (prefers-reduced-motion: reduce) {
  .glass { transition: none; }
  .liquid { filter: none; }                   /* 停止折射动画 */
}
@supports not (backdrop-filter: blur(1px)) {
  .glass { background: rgba(30,30,50,.85); }  /* 足够不透明的降级方案 */
}

在繁忙背景上的对比度:照片上的半透明面板可能使文本低于WCAG标准。在文本下方添加半透明遮罩或加深渐变,可选 text-shadow: 0 1px 2px rgba(0,0,0,.4),并验证正文文本对比度 ≥ 4.5:1 / 大文本 ≥ 3:1(相对于背景最亮区域)。

交付与验证(独立HTML)

打包的辅助脚本(scripts/):scripts/seek-shot.sh anim.html 0 1.5 3 冻结 ?t=N 测试环境并截取每个时刻的截图;scripts/contact-sheet.sh sheet.png frame-*.png 将它们拼成平铺图以便一目了然的审查。详见 scripts/README.md。

对于独立的玻璃演示(卡片、导航栏、模态框、液态玻璃英雄区),交付物应为一个可以直接在浏览器中打开的HTML文件——包含标记、CSS,以及(如果是液态玻璃)一个内联SVG滤镜,无需构建步骤。单个文件对于玻璃表面来说是合适的层级;不要使用打包工具。面板必须覆盖在真实的背景之上(插入一张图片或渐变),否则没有东西可模糊,演示就是骗人的。

输出约定:

  • 一个 .html 文件:一个繁忙的背景、你的玻璃标记、CSS(霜面 + 边缘高光 + 噪点 + 阴影),以及任何内联的 SVG feDisplacementMap 滤镜。
  • 一种方式可以定位到已解析状态和任何循环的冻结帧——玻璃通过状态(静止/悬停/进入)和时间(扫描/折射)来进行验证。
  • 包含下面的冻结工具,以便任何时刻都可以被固定下来供审查。

定位工具 — 固定确定性的状态和帧。 ?state=hover 强制悬停样式;?t=N 在 N 秒处冻结CSS动画和SVG折射,以便截图落在静止、确定的帧上:

<script>
  const p = new URLSearchParams(location.search);
  const state = p.get("state");
  if (state) document.documentElement.dataset.state = state;   // CSS 通过 :root[data-state="hover"] 起作用
  const t = p.get("t");
  if (t !== null) {
    document.getAnimations().forEach(a => { a.currentTime = parseFloat(t)*1000; a.pause(); }); // 冻结CSS扫描
    const svg = document.querySelector("svg");
    svg?.pauseAnimations?.(); svg?.setCurrentTime?.(parseFloat(t));                            // 冻结折射
  }
  window.__ready = true;
</script>

验证循环 — 渲染 → 设置状态/冻结 → 截图 → 检查: 打开每个有意义的状态(?state=rest、?state=hover)和一个冻结的循环帧(?t=2),截图,并确认玻璃看起来像玻璃——模糊和边缘高光可见,无颜色条带,文本对比度在背景之上保持——同时检查问题(因为背景是纯色而导致平面盒子、Safari中缺少 -webkit- 前缀、折射过强/熔化、动画化模糊导致卡顿)。然后加载 prefers-reduced-transparency 并确认实心降级渲染可读。任何无头工具都可以:

npx playwright screenshot --wait-for-timeout=500 "file://$PWD/glass.html?state=hover" hover.png
npx playwright screenshot --wait-for-timeout=500 "file://$PWD/glass.html?t=2"          loop.png

要无头检查降级方案,模拟媒体特性(例如 Playwright 的 --color-scheme 风格标志,或一个切换与媒体查询镜像类名的 ?reduced=1 查询参数),并截图确认面板是实心的且可读。

在完成之前:

  1. 独立打开 — 无控制台错误;玻璃覆盖在真实的繁忙背景之上,而非纯色。
  2. 看起来像玻璃 — 模糊 + 明亮边缘高光都可见,层叠阴影使其悬浮,无条带(有噪点)。
  3. 文本对比度在背景最亮部分之上保持(正文 ≥ 4.5:1)。
  4. ?state= / ?t=N 冻结产生确定、稳定的帧。
  5. prefers-reduced-transparency → 实心不透明面板;prefers-reduced-motion → 折射/扫描停止;@supports 针对无 backdrop-filter 的降级方案。
  6. 性能合理 — 玻璃数量有限,模糊不在卡顿路径上动画化,液态折射仅在一个元素上使用。

快速参考

需求方法
基础霜面backdrop-filter: blur(16px) saturate(160%) + alpha 背景
玻璃边缘更亮的 border + 带遮罩的 ::before 发光角环
悬浮/深度box-shadow 投影 + inset 顶部高光和底部阴影
消除条带feTurbulence 噪点 ::after,opacity ≤ .06
悬停动效过渡 transform/box-shadow/background,模糊变化量小
进入动效@starting-style { backdrop-filter: blur(0); opacity:0 }
液态折射feDisplacementMap ← 动画化的 feTurbulence,通过 filter 应用
镜面扫描在表面上动画化倾斜的白色渐变
Safari始终配对使用 -webkit-backdrop-filter
减少透明度实心不透明面板,去掉噪点
无 backdrop-filter@supports not (...) 足够不透明的降级方案

参考文件

  • references/glass-recipes.md — 完整的复制粘贴配方:带级别的基础玻璃卡片、带遮罩的镜面边缘环、抗条带噪点、悬停/进入/滚动动效、镜面扫描、包含调优参数的 SVG feDisplacementMap/feTurbulence 液态玻璃滤镜、性能规则、减少透明度/减少动效/@supports 降级方案、对比度防御以及独立的冻结工具。

Individual skills in this repo

This repo contains 13 individual skills — each has its own dedicated page.

nehakanjamala/personal_website

This skill should be used when the user asks to "fix janky CSS animation", "make animation 60fps", "stop layout thrashing", "animate width/height/top/left smoothly", "convert animation to transform", "animate box-shadow performantly", "animate height auto", "FLIP animation", or "why is my scroll/hover animation choppy".

nehakanjamala/personal_website

This skill should be used when the user asks to "respect prefers-reduced-motion", "honor reduced motion", "make my animations accessible", "fix vestibular / motion-sickness issues", "add a useReducedMotion hook", "gate GSAP / Framer Motion / Lenis for reduced motion", or "meet WCAG 2.3.3 / C39". Provides tiered (not all-or-nothing) reduced-motion patterns in CSS and JS.

nehakanjamala/personal_website

Create, modify, debug, and deploy Apify Actors, and write their input and output schemas. Use when building an Actor from scratch, changing or troubleshooting Actor code, generating or updating .actor schema files, or pushing an Actor to the Apify platform. To wrap an existing non-Actor project, use apify-actorization instead.

nehakanjamala/personal_website

Convert existing projects into Apify Actors - serverless cloud programs. Actorize JavaScript/TypeScript (SDK with Actor.init/exit), Python (async context manager), or any language (CLI wrapper). Use when migrating code to Apify, wrapping CLI tools as Actors, or adding Actor SDK to existing projects.

nehakanjamala/personal_website

Deprecated. Output schema generation moved to the apify-actor-development skill; prefer that skill whenever it is available.

nehakanjamala/personal_website

Design and build an official Apify integration for a company's product - workflow-automation apps (Zapier/n8n-style), AI agent plugins (coding-agent skills+MCP bundles or OpenClaw/Hermes-style harnesses), AI framework packages (LangChain/LlamaIndex-style), or direct application clients via apify-client. Use when planning, creating, or reviewing an integration that exposes Apify Actors, runs, datasets, or key-value stores inside another product.

nehakanjamala/personal_website

Universal AI-powered web scraper for any platform. Scrape data from Instagram, Facebook, TikTok, YouTube, LinkedIn, X/Twitter, Google Maps, Google Search, Google Trends, Reddit, Airbnb, Yelp, and 15+ more platforms. Use for lead generation, brand monitoring, competitor analysis, influencer discovery, trend research, content analytics, audience analysis, review analysis, SEO intelligence, recruitment, or any data extraction task.

nehakanjamala/personal_website

This skill should be used when the user asks to "build a scroll animation", "add ScrollTrigger", "pin a section while scrolling", "scrub an animation to scroll", "create a hero timeline", "do a horizontal scroll section", "split text and animate words", "animate a layout change with GSAP Flip", "sync ScrollTrigger with Lenis", "Lenis smooth scroll jittery", "ScrollTrigger markers drift", "ScrollTrigger pins break with Lenis/Locomotive", or "set up smooth scroll with GSAP pinning". Covers GSAP timelines, ScrollTrigger, SplitText, Flip, and Lenis/Locomotive smooth-scroll sync for code-driven web motion.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a Lottie animation", "play a .lottie or .json animation", "integrate a Bodymovin/After Effects animation on web or mobile", "control Lottie playback / segments", "make a scroll-driven Lottie", "recolor a Lottie at runtime", or "export an AE animation to Lottie". Covers dotLottie/lottie-web integration, playback control, interactivity, theming, and the AE export checklist.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a hover/press effect", "animate a toggle or switch", "build an animated like button", "make a toast/snackbar slide in", "animate a drawer or modal", "animate list reordering or add/remove", "do a shared-element layout transition", or "polish UI feedback". Covers UI motion with Framer Motion (motion/react) and modern CSS.

nehakanjamala/personal_website

This skill should be used when the user asks to "animate page or route transitions", "add a page transition or crossfade between views", "animate route changes in Next.js App Router", "use the View Transitions API", "AnimatePresence exit doesn't fire on navigation", or "Framer Motion exit animation not working / exit animation before unmount in Next.js". Covers enter/exit page-transition animation with the View Transitions API and Framer Motion, for Next.js App Router and general SPA routing.

nehakanjamala/personal_website

Scrape web pages using Scrapling with anti-bot bypass (like Cloudflare Turnstile), stealth headless browsing, spiders framework, adaptive scraping, and JavaScript rendering. Use when asked to scrape, crawl, or extract data from websites; web_fetch fails; the site has anti-bot protections; write Python code to scrape/crawl; or write spiders.

nehakanjamala/personal_website

This skill should be used when the user asks to "animate an SVG", "make a line draw itself on", "do a stroke draw-on / signature animation", "morph one shape into another", "move an element along a path", "animate an icon/logo", or "animate an SVG gradient or filter". Covers stroke-dashoffset draw-on, path morphing, motion-along-path, and animated icons/gradients/filters via CSS, SMIL, and GSAP.

相关技能