设为首页收藏本站
网站公告 | 这是第一条公告
     

 找回密码
 立即注册
缓存时间01 现在时间01 缓存数据 当你走完一段之后回头看,你会发现,那些真正能被记得的事真的是没有多少,真正无法忘记的人屈指可数,真正有趣的日子不过是那么一些,而真正需要害怕的也是寥寥无几。

当你走完一段之后回头看,你会发现,那些真正能被记得的事真的是没有多少,真正无法忘记的人屈指可数,真正有趣的日子不过是那么一些,而真正需要害怕的也是寥寥无几。

查看: 995|回复: 0

Vue实现液态玻璃登录卡片的效果示例

[复制链接]

  离线 

TA的专栏

  • 打卡等级:热心大叔
  • 打卡总天数:229
  • 打卡月天数:1
  • 打卡总奖励:3383
  • 最近打卡:2025-12-03 20:53:34
等级头衔

等級:晓枫资讯-上等兵

在线时间
0 小时

积分成就
威望
0
贡献
420
主题
396
精华
0
金钱
4675
积分
879
注册时间
2023-1-6
最后登录
2025-12-3

发表于 2025-9-11 08:49:03 | 显示全部楼层 |阅读模式
效果介绍

液态玻璃(Liquid Glass)是一种极具现代感的UI视觉风格,常见于高端网站和操作系统界面。它通过多层叠加、模糊、光泽、滤镜等技术,模拟出玻璃的通透、折射和高光质感。苹果的这次系统设计更新,带火了这一设计效果,本教程将带你一步步实现一个带有3D灵动倾斜交互的液态玻璃登录卡片。
实际效果:
1.webp


技术原理解析


1. 多层叠加

液态玻璃效果的核心是多层视觉叠加:

  • 模糊层(blur):让背景内容变得虚化,产生玻璃的通透感。
  • 色调层(tint):为玻璃加上一层淡淡的色彩,提升质感。
  • 高光层(shine):模拟玻璃边缘的高光和内阴影,增强立体感。
  • SVG滤镜:通过 SVG 的
    1. feTurbulence
    复制代码
    1. feDisplacementMap
    复制代码
    ,让玻璃表面产生微妙的扭曲和流动感。

2. 3D灵动倾斜

通过监听鼠标在卡片上的移动,动态计算并设置
  1. transform: perspective(...) rotateX(...) rotateY(...)
复制代码
,让卡片随鼠标灵动倾斜,增强交互体验。

3. 背景与环境

背景可以是渐变色,也可以是图片。玻璃卡片通过
  1. backdrop-filter
复制代码
与背景内容产生交互,形成真实的玻璃质感。

实现步骤详解


1. 结构搭建
  1. <template>
  2.   <div class="login-container animated-background">
  3.     <!-- SVG滤镜库 -->
  4.     <svg style="display: none">...</svg>
  5.     <!-- 登录卡片 -->
  6.     <div
  7.       class="glass-component login-card"
  8.       ref="tiltCard"
  9.       @mousemove="handleMouseMove"
  10.       @mouseleave="handleMouseLeave"
  11.     >
  12.       <div class="glass-effect"></div>
  13.       <div class="glass-tint"></div>
  14.       <div class="glass-shine"></div>
  15.       <div class="glass-content">
  16.         <!-- 登录表单内容 -->
  17.       </div>
  18.     </div>
  19.   </div>
  20. </template>
复制代码
2. SVG滤镜实现液态扭曲
  1. <svg style="display: none">
  2.   <filter id="glass-distortion" x="0%" y="0%" width="100%" height="100%" filterUnits="objectBoundingBox">
  3.     <feTurbulence type="fractalNoise" baseFrequency="0.001 0.005" numOctaves="1" seed="17" result="turbulence" />
  4.     <feComponentTransfer in="turbulence" result="mapped">
  5.       <feFuncR type="gamma" amplitude="1" exponent="10" offset="0.5" />
  6.       <feFuncG type="gamma" amplitude="0" exponent="1" offset="0" />
  7.       <feFuncB type="gamma" amplitude="0" exponent="1" offset="0.5" />
  8.     </feComponentTransfer>
  9.     <feGaussianBlur in="turbulence" stdDeviation="3" result="softMap" />
  10.     <feSpecularLighting in="softMap" aceScale="5" specularConstant="1" specularExponent="100" lighting-color="white" result="specLight">
  11.       <fePointLight x="-200" y="-200" z="300" />
  12.     </feSpecularLighting>
  13.     <feComposite in="specLight" operator="arithmetic" k1="0" k2="1" k3="1" k4="0" result="litImage" />
  14.     <feDisplacementMap in="SourceGraphic" in2="softMap" scale="200" xChannelSelector="R" yChannelSelector="G" />
  15.   </filter>
  16. </svg>
复制代码

  • 这段 SVG 代码必须放在页面结构内,供 CSS filter 调用。

3. 背景设置
  1. .animated-background {
  2.   width: 100vw;
  3.   height: 100vh;
  4.   background-image: url('你的背景图片路径');
  5.   background-size: cover;
  6.   background-position: center;
  7.   background-repeat: no-repeat;
  8.   position: fixed;
  9.   top: 0;
  10.   left: 0;
  11.   z-index: -1;
  12. }
复制代码

  • 建议用高质量渐变或壁纸,能更好衬托玻璃质感。

4. 卡片多层玻璃结构
  1. .login-card {
  2.   width: 400px;
  3.   border-radius: 24px;
  4.   overflow: hidden;
  5.   box-shadow: 0 4px 24px 0 rgba(0,0,0,0.10), 0 1.5px 6px 0 rgba(0,0,0,0.08);
  6.   background: transparent;
  7.   position: relative;
  8. }
  9. .glass-effect {
  10.   position: absolute;
  11.   inset: 0;
  12.   z-index: 0;
  13.   backdrop-filter: blur(5px);
  14.   filter: url(#glass-distortion);
  15.   isolation: isolate;
  16.   border-radius: 24px;
  17. }
  18. .glass-tint {
  19.   position: absolute;
  20.   inset: 0;
  21.   z-index: 1;
  22.   background: rgba(0, 0, 0, 0.15);
  23.   border-radius: 24px;
  24. }
  25. .glass-shine {
  26.   position: absolute;
  27.   inset: 0;
  28.   z-index: 2;
  29.   border: 1px solid rgba(255, 255, 255, 0.13);
  30.   border-radius: 24px;
  31.   box-shadow:
  32.     inset 1px 1px 8px 0 rgba(255, 255, 255, 0.18),
  33.     inset -1px -1px 8px 0 rgba(255, 255, 255, 0.08);
  34.   pointer-events: none;
  35. }
  36. .glass-content {
  37.   position: relative;
  38.   z-index: 3;
  39.   padding: 2rem;
  40.   color: white;
  41. }
复制代码

  • 每一层都要有一致的 border-radius,才能保证圆角处无割裂。

5. 3D灵动倾斜交互
  1. methods: {
  2.   handleMouseMove (e) {
  3.     const card = this.$refs.tiltCard
  4.     const rect = card.getBoundingClientRect()
  5.     const x = e.clientX - rect.left
  6.     const y = e.clientY - rect.top
  7.     const centerX = rect.width / 2
  8.     const centerY = rect.height / 2
  9.     const maxTilt = 18
  10.     const rotateY = ((x - centerX) / centerX) * maxTilt
  11.     const rotateX = -((y - centerY) / centerY) * maxTilt
  12.     card.style.transform = `perspective(600px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale(1.03)`
  13.   },
  14.   handleMouseLeave () {
  15.     const card = this.$refs.tiltCard
  16.     card.style.transform = 'perspective(600px) rotateX(0deg) rotateY(0deg) scale(1)'
  17.   }
  18. }
复制代码

  • 鼠标移动时,卡片会根据指针位置灵动倾斜。
  • 鼠标移出时,卡片平滑恢复。

6. 细节优化


  • 阴影柔和:避免黑色边缘过重,提升高级感。
  • 高光线条:用低透明度白色边框和内阴影,模拟玻璃高光。
  • 所有层的圆角一致:防止割裂。
  • 表单输入框:用半透明背景和模糊,保持整体风格统一。

7.完整代码
  1. <template>
  2.   <div class="login-container animated-background">
  3.     <!-- SVG滤镜库 -->
  4.     <svg style="display: none">
  5.       <filter id="glass-distortion" x="0%" y="0%" width="100%" height="100%" filterUnits="objectBoundingBox">
  6.         <feTurbulence type="fractalNoise" baseFrequency="0.001 0.005" numOctaves="1" seed="17" result="turbulence" />
  7.         <feComponentTransfer in="turbulence" result="mapped">
  8.           <feFuncR type="gamma" amplitude="1" exponent="10" offset="0.5" />
  9.           <feFuncG type="gamma" amplitude="0" exponent="1" offset="0" />
  10.           <feFuncB type="gamma" amplitude="0" exponent="1" offset="0.5" />
  11.         </feComponentTransfer>
  12.         <feGaussianBlur in="turbulence" stdDeviation="3" result="softMap" />
  13.         <feSpecularLighting in="softMap" aceScale="5" specularConstant="1" specularExponent="100" lighting-color="white" result="specLight">
  14.           <fePointLight x="-200" y="-200" z="300" />
  15.         </feSpecularLighting>
  16.         <feComposite in="specLight" operator="arithmetic" k1="0" k2="1" k3="1" k4="0" result="litImage" />
  17.         <feDisplacementMap in="SourceGraphic" in2="softMap" scale="200" xChannelSelector="R" yChannelSelector="G" />
  18.       </filter>
  19.     </svg>

  20.     <!-- 登录卡片 -->
  21.     <div
  22.       class="glass-component login-card"
  23.       ref="tiltCard"
  24.       @mousemove="handleMouseMove"
  25.       @mouseleave="handleMouseLeave"
  26.     >
  27.       <div class="glass-effect"></div>
  28.       <div class="glass-tint"></div>
  29.       <div class="glass-shine"></div>
  30.       <div class="glass-content">
  31.         <h2 class="login-title">欢迎登录</h2>
  32.         <form class="login-form">
  33.           <div class="form-group">
  34.             <input type="text" placeholder="用户名" class="glass-input">
  35.           </div>
  36.           <div class="form-group">
  37.             <input type="password" placeholder="密码" class="glass-input">
  38.           </div>
  39.           <button type="submit" class="glass-button">登录</button>
  40.         </form>
  41.       </div>
  42.     </div>
  43.   </div>
  44. </template>

  45. <script>
  46. export default {
  47.   name: 'LiquidGlass',
  48.   data () {
  49.     return {
  50.       // 可以添加需要的数据
  51.     }
  52.   },
  53.   methods: {
  54.     handleMouseMove (e) {
  55.       const card = this.$refs.tiltCard
  56.       const rect = card.getBoundingClientRect()
  57.       const x = e.clientX - rect.left
  58.       const y = e.clientY - rect.top
  59.       const centerX = rect.width / 2
  60.       const centerY = rect.height / 2
  61.       // 最大旋转角度
  62.       const maxTilt = 18
  63.       const rotateY = ((x - centerX) / centerX) * maxTilt
  64.       const rotateX = -((y - centerY) / centerY) * maxTilt
  65.       card.style.transform = `perspective(600px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale(1.03)`
  66.     },
  67.     handleMouseLeave () {
  68.       const card = this.$refs.tiltCard
  69.       card.style.transform = 'perspective(600px) rotateX(0deg) rotateY(0deg) scale(1)'
  70.     }
  71.   }
  72. }
  73. </script>

  74. <style lang="scss" scoped>
  75. .login-container {
  76.   min-height: 100vh;
  77.   display: flex;
  78.   align-items: center;
  79.   justify-content: center;
  80.   position: relative;
  81.   overflow: hidden;
  82. }

  83. .animated-background {
  84.   width: 100%;
  85.   height: 100%;
  86.   background-image: url('../../assets/macwallpaper.jpg');
  87.   background-size: cover;
  88.   background-position: center;
  89.   background-repeat: no-repeat;
  90. }

  91. .login-card {
  92.   width: 400px;
  93.   position: relative;
  94.   border-radius: 24px;
  95.   overflow: hidden;
  96.   box-shadow: 0 4px 24px 0 rgba(0,0,0,0.10), 0 1.5px 6px 0 rgba(0,0,0,0.08);
  97.   transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.6);
  98.   cursor: pointer;
  99.   background: transparent;
  100. }

  101. .glass-effect {
  102.   position: absolute;
  103.   inset: 0;
  104.   z-index: 0;
  105.   backdrop-filter: blur(5px);
  106.   filter: url(#glass-distortion);
  107.   isolation: isolate;
  108.   border-radius: 24px;
  109. }

  110. .glass-tint {
  111.   position: absolute;
  112.   inset: 0;
  113.   z-index: 1;
  114.   background: rgba(0, 0, 0, 0.15);
  115.   border-radius: 24px;
  116. }

  117. .glass-shine {
  118.   position: absolute;
  119.   inset: 0;
  120.   z-index: 2;
  121.   border: 1px solid rgba(255, 255, 255, 0.13);
  122.   border-radius: 24px;
  123.   box-shadow:
  124.     inset 1px 1px 8px 0 rgba(255, 255, 255, 0.18),
  125.     inset -1px -1px 8px 0 rgba(255, 255, 255, 0.08);
  126.   pointer-events: none;
  127. }

  128. .glass-content {
  129.   position: relative;
  130.   z-index: 3;
  131.   padding: 2rem;
  132.   color: white;
  133. }

  134. .login-title {
  135.   text-align: center;
  136.   color: #fff;
  137.   margin-bottom: 2rem;
  138.   font-size: 2rem;
  139.   font-weight: 600;
  140.   text-shadow: 0 1px 3px rgba(0,0,0,0.2);
  141. }

  142. .form-group {
  143.   margin-bottom: 1.5rem;
  144. }

  145. .glass-input {
  146.   width: 90%;
  147.   padding: 12px 20px;
  148.   border: none;
  149.   border-radius: 10px;
  150.   background: rgba(255, 255, 255, 0.1);
  151.   color: #fff;
  152.   font-size: 1rem;
  153.   backdrop-filter: blur(5px);
  154.   transition: all 0.3s ease;

  155.   &::placeholder {
  156.     color: rgba(255, 255, 255, 0.7);
  157.   }

  158.   &:focus {
  159.     outline: none;
  160.     background: rgba(255, 255, 255, 0.2);
  161.     box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
  162.   }
  163. }

  164. .glass-button {
  165.   width: 100%;
  166.   padding: 12px;
  167.   border: none;
  168.   border-radius: 10px;
  169.   background: rgba(255, 255, 255, 0.2);
  170.   color: #fff;
  171.   font-size: 1rem;
  172.   font-weight: 600;
  173.   cursor: pointer;
  174.   transition: all 0.3s ease;
  175.   backdrop-filter: blur(5px);
  176.   position: relative;
  177.   overflow: hidden;

  178.   &:hover {
  179.     background: rgba(255, 255, 255, 0.3);
  180.     transform: translateY(-2px);
  181.     box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
  182.   }

  183.   &:active {
  184.     transform: translateY(0);
  185.   }
  186. }

  187. // 添加点击波纹效果
  188. .click-gradient {
  189.   position: absolute;
  190.   border-radius: 50%;
  191.   background: radial-gradient(circle, rgba(255,255,255,0.4) 0%, rgba(180,180,255,0.2) 40%, rgba(100,100,255,0.1) 70%, rgba(50,50,255,0) 100%);
  192.   transform: translate(-50%, -50%) scale(0);
  193.   opacity: 0;
  194.   pointer-events: none;
  195.   z-index: 4;
  196. }

  197. .glass-component.clicked .click-gradient {
  198.   animation: gradient-ripple 0.6s ease-out;
  199. }

  200. @keyframes gradient-ripple {
  201.   0% {
  202.     transform: translate(-50%, -50%) scale(0);
  203.     opacity: 1;
  204.   }
  205.   100% {
  206.     transform: translate(-50%, -50%) scale(3);
  207.     opacity: 0;
  208.   }
  209. }

  210. .glass-component {
  211.   transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  212.   will-change: transform;
  213. }
  214. </style>
复制代码
常见问题与优化建议


  • 阴影过重/黑边:减小 box-shadow 的透明度和模糊半径。
  • 圆角割裂:所有玻璃层都要加 border-radius。
  • 背景不通透:确保 glass-effect 层有 blur 和 SVG filter。
  • 性能问题:backdrop-filter 在低端设备上可能有性能损耗,建议只在必要区域使用。
  • 浏览器兼容性:backdrop-filter 需现代浏览器支持,IE/部分安卓浏览器不兼容。

技术要点总结


  • SVG滤镜:让玻璃表面有微妙的流动和扭曲感。
  • backdrop-filter: blur:实现背景虚化。
  • 多层叠加:色调、高光、阴影共同营造真实玻璃质感。
  • 3D transform:提升交互体验。
  • 细节打磨:阴影、边框、圆角、色彩都要精细调整。

结语

液态玻璃效果是现代前端视觉的代表之一。只要理解其原理,分层实现、细致调优,任何人都能做出媲美 macOS、Win11 的高端玻璃UI。希望本教程能帮助你掌握这项技术,做出属于自己的酷炫界面!
到此这篇关于Vue实现一个“液态玻璃”效果登录卡片的文章就介绍到这了,更多相关Vue实现液态玻璃登录卡片内容请搜索晓枫资讯以前的文章或继续浏览下面的相关文章希望大家以后多多支持晓枫资讯!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
晓枫资讯-科技资讯社区-免责声明
免责声明:以上内容为本网站转自其它媒体,相关信息仅为传递更多信息之目的,不代表本网观点,亦不代表本网站赞同其观点或证实其内容的真实性。
      1、注册用户在本社区发表、转载的任何作品仅代表其个人观点,不代表本社区认同其观点。
      2、管理员及版主有权在不事先通知或不经作者准许的情况下删除其在本社区所发表的文章。
      3、本社区的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,举报反馈:点击这里给我发消息进行删除处理。
      4、本社区一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
      5、以上声明内容的最终解释权归《晓枫资讯-科技资讯社区》所有。
http://bbs.yzwlo.com 晓枫资讯--游戏IT新闻资讯~~~
严禁发布广告,淫秽、色情、赌博、暴力、凶杀、恐怖、间谍及其他违反国家法律法规的内容。!晓枫资讯-社区
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|晓枫资讯--科技资讯社区 本站已运行

CopyRight © 2022-2025 晓枫资讯--科技资讯社区 ( BBS.yzwlo.com ) . All Rights Reserved .

晓枫资讯--科技资讯社区

本站内容由用户自主分享和转载自互联网,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。

如有侵权、违反国家法律政策行为,请联系我们,我们会第一时间及时清除和处理! 举报反馈邮箱:点击这里给我发消息

Powered by Discuz! X3.5

快速回复 返回顶部 返回列表