CSS100Day(8)-水滴液态融合两个filter属性理解

1276 字
6 分钟
CSS100Day(8)-水滴液态融合两个filter属性理解

设计简介#

设计一个大水滴,然后内部8个元素旋转展示“摔的感觉”,外部6个元素旋转,旋转出去和回来使用transform-origin实现

  • 核心知识1:融合效果也称之为Gooey Effect效果,核心是filter属性的两个函数配合,缺一不可

    关键组合是:filter: contrast() + filter: blur(),分别作用在不同层级

    属性作用层级作用
    filter: contrast(20-30)父容器提高整体对比度,强制将子元素边缘模糊收缩回来,
    边缘被吸收的感觉,从而呈现融合的液态感觉
    filter: blur(2px-10px)子元素让元素边缘模糊,产生向外扩散的“粘性边缘”
  • 其他知识2:

效果展示#

实现代码和步骤#

HTML部分#

容器.frame设计超大对比度filter:contrast(25)

一个中心圆当做filter: blur(15)大一点吸收边缘模糊,8个小球扩展中心圆,起到弹性效果

另外6个球改变transform-origin,在外部rotate摔出然后回来融合

<div class="frame">
<div class="center">
<div class="ball"></div>
<div class="blubb-1"></div>
<div class="blubb-2"></div>
<div class="blubb-3"></div>
<div class="blubb-4"></div>
<div class="blubb-5"></div>
<div class="blubb-6"></div>
<div class="blubb-7"></div>
<div class="blubb-8"></div>
<div class="sparkle-1"></div>
<div class="sparkle-2"></div>
<div class="sparkle-3"></div>
<div class="sparkle-4"></div>
<div class="sparkle-5"></div>
<div class="sparkle-6"></div>
</div>
</div>

CSS部分#

首先外部大容器作为大对比度容器

.frame {
width: 400px;
height: 400px;
box-shadow: 1px 2px 10px 0 rgba(0, 0, 0, 0.3);
background-color: #000;
border-radius: 2px;
filter: contrast(25);
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

然后中心园,边缘模糊强烈一点filter: blur(15px)

.ball {
position: relative;
width: 90px;
height: 90px;
background-color: #fff;
border-radius: 50%;
filter: blur(15px);
}

内部八个小球,边缘较小模糊filter: blur(5px);transform-origin不超过大圆球,导致圆球边缘有突出感觉

.blubb-1,
.blubb-2,
.blubb-3,
.blubb-4,
.blubb-5,
.blubb-6,
.blubb-7,
.blubb-8 {
position: absolute;
top: 20px;
left: 20px;
width: 50px;
height: 50px;
&::after {
position: absolute;
display: block;
content: "";
width: 50px;
height: 50px;
background-color: #fff;
border-radius: 50%;
filter: blur(5px);
}
}
.blubb-1 {
rotate: 250deg;
&::after {
transform-origin: 37px 37px;
animation: rotate 2.6s ease-in-out infinite;
}
}
.blubb-2 {
rotate: 150deg;
&::after {
transform-origin: 34px 34px;
animation: rotate 2.8s ease-in-out infinite;
}
}
.blubb-3 {
rotate: 150deg;
&::after {
transform-origin: 31px 31px;
animation: rotate 2.9s ease-in-out infinite;
}
}
.blubb-4 {
rotate: 150deg;
&::after {
transform-origin: 28px 28px;
animation: rotate 3s ease-in-out infinite;
}
}
.blubb-5 {
rotate: 150deg;
&::after {
transform-origin: 25px 25px;
animation: rotate 3.2s ease-in-out infinite;
}
}
.blubb-6 {
rotate: 150deg;
&::after {
transform-origin: 22px 22px;
animation: rotate 3.3s ease-in-out infinite;
}
}
.blubb-7 {
rotate: 150deg;
&::after {
transform-origin: 19px 19px;
animation: rotate 3.4s ease-in-out infinite;
}
}
.blubb-8 {
rotate: 150deg;
&::after {
transform-origin: 16px 16px;
animation: rotate 3.6s ease-in-out infinite;
}
}

外部6个球,大小随机边缘小模糊filter: blur(3px);transform-origin较大超过大圆球,注意设置animation-delay达到不同步效果

.sparkle-1,
.sparkle-2,
.sparkle-3,
.sparkle-4,
.sparkle-5,
.sparkle-6 {
position: absolute;
top: 38px;
left: 38px;
&::after {
position: absolute;
display: block;
content: "";
background-color: #fff;
border-radius: 50%;
filter: blur(3px);
}
}
.sparkle-1 {
width: 8px;
height: 8px;
transform: rotate(260deg);
&::after {
width: 8px;
height: 8px;
transform-origin: 58px 58px;
animation: rotate 3.6s ease-in-out infinite;
animation-delay: 0.2s;
}
}
.sparkle-2 {
width: 9px;
height: 9px;
transform: rotate(120deg);
&::after {
width: 9px;
height: 9px;
transform-origin: 56px 56px;
animation: rotate 3.7s ease-in-out infinite;
animation-delay: 0.4s;
}
}
.sparkle-3 {
width: 13px;
height: 13px;
transform: rotate(96deg);
&::after {
width: 13px;
height: 13px;
transform-origin: 55px 55px;
animation: rotate 3.8s ease-in-out infinite;
animation-delay: 0.6s;
}
}
.sparkle-4 {
width: 16px;
height: 16px;
transform: rotate(315deg);
&::after {
width: 16px;
height: 16px;
transform-origin: 51px 51px;
animation: rotate 4s ease-in-out infinite;
animation-delay: 0.8s;
}
}
.sparkle-5 {
width: 14px;
height: 14px;
transform: rotate(50deg);
&::after {
width: 14px;
height: 14px;
transform-origin: 49px 49px;
animation: rotate 4.1s ease-in-out infinite;
animation-delay: 0.9s;
}
}
.sparkle-6 {
width: 18px;
height: 18px;
transform: rotate(225deg);
&::after {
width: 18px;
height: 18px;
transform-origin: 45px 45px;
animation: rotate 3.8s ease-in-out infinite;
animation-delay: 0.3s;
}
}
@keyframes rotate {
from {
transform: rotate(0deg) translate3d(0, 0, 0);
}
to {
transform: rotate(360deg) translate3d(0, 0, 0);
}
}
分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接

评论区

图片
犟哟
Hello, I'm Juyial.
公告
欢迎来到我的博客,在这里可以一起进步,一起学习!2026年起航!
分类
站点统计
文章
19
分类
1
标签
3
总字数
35,134
运行时长
0
最后活动
0 天前

目录