当前位置: 首页 > news >正文

有趣的css - 动态的毛玻璃背景

页面效果

此效果主要使用 backdrop-filter 属性,以及配合 animation 属性来实现毛玻璃模糊和一些动效。

此效果可适用于登录窗口,网站背景或者一些卡片列表中,使网页更具科技感和空间感。


核心代码部分,简要说明了写法思路;完整代码在最后,可直接复制到本地运行。

核心代码

html代码

<div class="box"><div class="circle-box"><div class="circle"></div><div class="circle"></div></div><div class="bg-filter"></div>
</div>

两个圆形 div(.circle),以及模糊块(.bg-filter)。

css代码

圆形部分主要样式

.circle-box{width: 100%;height: 100%;border-radius: 10px;position: absolute;overflow: hidden;  /* 限制溢出 */
}
.circle:first-child{width: 120px;height: 120px;border-radius: 50%;border: 30px solid #7BF52A;box-sizing: border-box;position: absolute;top: -38px;left: -40px;animation: move-y 3.5s linear infinite; /* 设置动画时间3.5s */
}
.circle:last-child{width: 120px;height: 120px;border-radius: 50%;background: linear-gradient(136deg, #7BF52A 0%, #FFCD56 100%);box-sizing: border-box;position: absolute;bottom: -30px;right: -30px;animation: move-y 5s ease-in-out infinite; /* 设置动画时长5s,与上一个圆环有差异,增强动效 */
}
/* 设置动画参数实现动效循环 */
@keyframes move-y {0% {transform: translateY(0);}50% {transform: translateY(-16px);}100% {transform: translateY(0);}
}

使用 animation 属性以及不同的参数来实现动效,产生动画视觉效果。

使用 backdrop-filter 属性模拟毛玻璃效果

.bg-filter{width: 100%;height: 100%;background: rgba(255,255,255,.05);box-shadow: 0 2px 6px rgba(0,0,0,0.1);backdrop-filter: blur(6px);  /* 用 blur 参数来模拟毛玻璃效果 */border-radius: 10px;box-sizing: border-box;position: absolute;
}

backdrop-filter 属性中的 blur 参数来模拟毛玻璃效果,数值越大,模糊效果越重,可适当调试参数,直到你喜欢为止。

完整代码

html页面

<!DOCTYPE html>
<html lang="zh"><head><meta charset="utf-8"><link rel="stylesheet" href="style.css"><title>动态的毛玻璃背景</title></head><body><div class="app"><div class="box"><div class="circle-box"><div class="circle"></div><div class="circle"></div></div><div class="bg-filter"></div></div></div></body>
</html>

css样式

.app{width: 100%;height: 100vh;position: relative;display: flex;justify-content: center;align-items: center;
}
.box{width: 400px;height: 300px;position: relative;
}
.circle-box{width: 100%;height: 100%;border-radius: 10px;position: absolute;overflow: hidden;
}
.circle:first-child{width: 120px;height: 120px;border-radius: 50%;border: 30px solid #7BF52A;box-sizing: border-box;position: absolute;top: -38px;left: -40px;animation: move-y 3.5s linear infinite;
}
.circle:last-child{width: 120px;height: 120px;border-radius: 50%;background: linear-gradient(136deg, #7BF52A 0%, #FFCD56 100%);box-sizing: border-box;position: absolute;bottom: -30px;right: -30px;animation: move-y 5s ease-in-out infinite;
}
.bg-filter{width: 100%;height: 100%;background: rgba(255,255,255,.05);box-shadow: 0 2px 6px rgba(0,0,0,0.1);backdrop-filter: blur(6px);border-radius: 10px;box-sizing: border-box;position: absolute;
}
@keyframes move-y {0% {transform: translateY(0);}50% {transform: translateY(-16px);}100% {transform: translateY(0);}
}

页面效果

以上就是全部代码以及写法思路了,希望你能喜欢,并且给你一些思路启发。


[1] 原文阅读

我是Just,这里是「设计师工作日常」,求点赞求关注!!!

http://www.lryc.cn/news/292125.html

相关文章:

  • 桥接模式解析
  • MySQL数据库基础第一篇(SQL通用语法与分类)
  • 【Qt学习笔记】(一)初识Qt
  • YIA主题如何关闭新版本升级提示?WordPress主题怎么取消升级提醒?
  • 消息队列的应用场景
  • Arcgis10.3安装
  • 用Python和 Cryptography库给你的文件加密解密
  • element-ui button 仿写 demo
  • Maya------创建多边形工具
  • SQL分组统计条数时,不存在组类型,如何显示条数为0
  • 通过日期计算星期函数(C语言版)
  • 配置支持 OpenAPI 的 ASP.NET Core 应用
  • 前端自己整理的学习面试笔记
  • jQuery html的使用
  • 锦上添花!特征选择+深度学习:mRMR-CNN-BiGRU-Attention故障识别模型!特征按重要性排序!最大相关最小冗余!
  • C++ QT入门2——记事本功能实现与优化(事件处理+基本控件)
  • 《Lua程序设计》-- 学习10
  • Linux内核编译-ARM
  • 开源编辑器:ONLYOFFICE文档又更新了!
  • 第3章 文件类型和目录结构
  • 前端构建变更:从 webpack 换 vite
  • 记录基于Vue.js的移动端Tree树形组件
  • Vue中嵌入原生HTML页面的方法
  • 17 # 类型检查机制:类型保护
  • Vulnhub-RIPPER: 1渗透
  • 幻兽帕鲁自建服务器:可以使用香港服务器吗?
  • Revisiting image pyramid structure for high resolution salient object detection
  • 中移(苏州)软件技术有限公司面试问题与解答(7)—— kmalloc与vmalloc的区别与联系及使用场景
  • 微服务-微服务Alibaba-Nacos 源码分析 (源码流程图)
  • 后端性能优化的一些总结