Communitygithub.com

Glassmorphism(磨砂玻璃與液態玻璃效果)

當用戶要求「加入玻璃擬態效果」、「磨砂玻璃 UI」、「Apple 液態玻璃風格」、「磨砂模糊卡片」、「半透明玻璃面板動畫」、「製作磨砂導航列」、「建立玻璃模態對話框」、「在懸停時讓玻璃卡片動起來」,或「添加折射液態玻璃英雄區」時,應使用此技能。涵蓋帶有 backdrop-filter 模糊效果的磨砂半透明面板、邊緣/高光反射、SVG 液態玻璃折射、懸停/滾動/進入時的動畫,以及無障礙的減少透明效果備援。

Glassmorphism(磨砂玻璃與液態玻璃效果) 是什麼?

此技能提供一套完整的方法,用於建立逼真的「玻璃擬態」(Glassmorphism)UI 元件,從經典的磨砂玻璃面板到 2026 年風格的「液態玻璃」效果。其核心在於模擬真實玻璃的四個必要屬性:半透明材質、背景模糊、明亮邊緣光暈與多層陰影所構成的浮動深度。技能不僅涵蓋基礎 CSS 實現(包含 backdrop-filter、邊框高光、box-shadow),更深入探討如何透過 SVG 濾鏡(feDisplacementMap 與 feTurbulence)製作背景折射效果,打造液態玻璃外觀。針對動畫,它強調應動畫玻璃本身的「質感」(如模糊程度、高光亮度、面板升降),而非幾何變形,並提供入場、懸停與鏡面掃描等動畫配方。效能方面,技能提醒限制玻璃元件數量、避免巢狀模糊、並為重負載元件建立獨立層。無障礙性是強制要求,必須提供 prefers-reduced-transparency 與 prefers-reduced-motion 的備援樣式,以及 @supports 的降級方案,確保在所有環境下內容皆清晰可讀。此外,技能包含一個完整的交付與驗證流程,要求產出獨立的 HTML 檔案,並內建凍結影格工具(透過 ?state= 與 ?t=N 查詢參數),以便精確截圖與檢驗每個狀態與時間點的渲染結果。此技能適用於任何需要高品質玻璃 UI 效果的網頁開發專案。

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

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Glassmorphism(磨砂玻璃與液態玻璃)

半透明、磨砂的 UI:你可以看穿的面板,背景經過模糊處理,呈現柔和的色彩,邊緣有一圈明亮的反光,浮在多層陰影之上。2026 年的「液態玻璃」進化版增加了折射效果——背景會明顯地透過面板彎曲——再加上移動的高光。目標是深度和材質感,而不僅僅是透明度。

使用時機

  • 在繁忙/照片背景上使用的磨砂卡片、導航列、側邊欄、模態對話框和工具列
  • 登入/英雄面板和覆蓋層,應呈現分層在頁面之上的感覺
  • Apple 風格的「液態玻璃」英雄區:緩慢流動、帶有高光掃掠的折射表面
  • 懸停/滾動/進入動畫——磨砂加深、高光變亮、面板升起
  • 任何內容需要呈現浮動玻璃感,同時保持可讀性的地方

真實玻璃的四個要素

玻璃從來不是單一屬性。每個面板都需要全部四項,否則看起來只是一個普通的半透明方塊:

  1. 磨砂 — backdrop-filter: blur() 加上 saturate(),讓背景顏色經過模糊後依然鮮明。
  2. 半透明 — 帶有 alpha 值的 background(約 0.08–0.18),不應完全不透明,也不應完全透明。
  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 以 opacity ≤ 0.06 疊加一層微弱的 feTurbulence 噪點覆蓋層,以抖動消除漸層的色階斷層(在強模糊下出現的階梯狀輪廓線)。完整的遮罩邊框和內聯噪點配方請參閱 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–20 秒),讓它像呼吸一樣。這些濾鏡很耗效能——只用在一個英雄元素上,不要在網格中使用。

效能——backdrop-filter 很昂貴

  • 每個玻璃元素都會重新取樣並模糊它後面的所有內容。限制數量;螢幕上同時出現十幾個會嚴重影響滾動 FPS。
  • 將重負載的玻璃提升到自己的圖層(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 會將 CSS 動畫和 SVG 折射凍結在 N 秒處,這樣截圖就能捕捉到一個靜止、確定的影格:

<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 bg
玻璃邊緣較亮的 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.

相關技能