本文介绍: 用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,这里是「设计师工作日常」,求点赞求关注!!!

原文地址:https://blog.csdn.net/justliu1989/article/details/135950985

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。

如若转载,请注明出处:http://www.7code.cn/show_64443.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注