CSS100Day(23)-动态字体动画设计

1123 字
6 分钟
CSS100Day(23)-动态字体动画设计

设计简介#

关键点如下

  1. 知识点1:transform-origin 可以使用animation动画,前面学习过使用margin auto实现,这里使用该方式更科学

  2. 知识点2:突然出现可以设计为一个隐藏元素先覆盖显示元素,然后隐藏元素 scale 变0

效果展示#

Collect
not things
moments

实现代码和步骤#

HTML部分#

<div class="frame">
<div class="circle"></div>
<div class="line left"></div>
<div class="line right"></div>
<div class="bracket left"></div>
<div class="bracket right"></div>
<div class="small top">Collect</div>
<div class="small bottom">not things</div>
<div class="big">moments</div>
<div class="hide top"></div>
<div class="hide bottom"></div>
</div>

CSS部分#

.frame {
width: 400px;
height: 400px;
box-shadow: 1px 2px 10px 0px rgba(0, 0, 0, 0.3);
overflow: hidden;
background: #e16d6c;
color: #fff;
position: relative;
}
.circle {
position: absolute;
z-index: 10;
top: 175px;
left: 175px;
background: #fff;
border-radius: 50%;
width: 50px;
height: 50px;
animation: circle 1s ease-in-out forwards;
}
.line {
position: absolute;
z-index: 10;
width: 150px;
height: 4px;
top: 198px;
background: #fff;
transform: scaleX(0);
&.left {
left: 50px;
transform-origin: 100% 50%;
animation:
lines 1s ease-in-out 0.8s,
line-left 1s steps(1) 0.8s;
}
&.right {
right: 50px;
transform-origin: 0% 50%;
animation:
lines 1s ease-in-out 0.8s,
line-right 1s steps(1) 0.8s;
}
}
.big {
position: absolute;
z-index: 5;
top: 173px;
width: 400px;
text-align: center;
font-weight: 800;
font-size: 50px;
color: #fff;
line-height: 50px;
text-transform: uppercase;
}
.hide {
position: absolute;
z-index: 7;
width: 400px;
height: 50px;
background: #e16d6c;
left: 0;
animation: reveal 0.4s ease-out 1.7s;
animation-fill-mode: both;
&.top {
bottom: 49%;
transform-origin: 50% 0%;
}
&.bottom {
top: 49%;
transform-origin: 50% 100%;
}
}
.bracket {
position: absolute;
z-index: 10;
height: 70px;
width: 4px;
top: 165px;
background: #fff;
animation: bracket 0.4s ease-out 1.7s both;
&::before,
&::after {
position: absolute;
display: block;
content: "";
width: 25px;
height: 4px;
background: #fff;
}
&.left {
left: 50px;
&::before {
top: 0;
left: 0;
transform-origin: 0% 50%;
animation: bracket-line 0.2s ease-out 2.1s;
animation-fill-mode: both;
}
&::after {
bottom: 0;
left: 0;
transform-origin: 0% 50%;
animation: bracket-line 0.2s ease-out 2.1s;
animation-fill-mode: both;
}
}
&.right {
right: 50px;
&::before {
top: 0;
right: 0;
transform-origin: 100% 50%;
animation: bracket-line 0.2s ease-out 2.1s;
animation-fill-mode: both;
}
&::after {
bottom: 0;
right: 0;
transform-origin: 100% 50%;
animation: bracket-line 0.2s ease-out 2.1s;
animation-fill-mode: both;
}
}
}
.small {
position: absolute;
z-index: 10;
width: 400px;
text-align: center;
left: 0;
font-weight: 300;
font-size: 30px;
color: #fff;
line-height: 30px;
text-transform: uppercase;
&.top {
top: 140px;
animation: small-top 0.5s ease-out 2.2s both;
}
&.bottom {
bottom: 140px;
animation: small-bottom 0.5s ease-out 2.2s both;
}
}
@keyframes circle {
0% {
scale: 1;
}
50% {
scale: 1.2;
}
90%,
100% {
scale: 0;
}
}
@keyframes lines {
0% {
transform: scaleX(0);
}
50% {
transform: scaleX(1);
}
100% {
transform: scaleX(0);
}
}
@keyframes line-left {
0% {
transform-origin: 100% 50%;
}
50% {
transform-origin: 0% 50%;
}
}
@keyframes line-right {
0% {
transform-origin: 0% 50%;
}
50% {
transform-origin: 100% 50%;
}
}
@keyframes bracket {
from {
transform: scaleY(0);
}
to {
transform: scaleY(1);
}
}
@keyframes bracket-line {
from {
transform: scaleX(0);
}
to {
transform: scaleX(1);
}
}
@keyframes reveal {
0% {
transform: scaleY(1);
}
100% {
transform: scaleY(0);
}
}
@keyframes small-top {
0% {
opacity: 0;
transform: translateX(-50px);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
@keyframes small-bottom {
0% {
opacity: 0;
transform: translateX(50px);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
@keyframes big {
from {
transform: scaleY(0);
}
to {
transform: scaleY(1);
}
}
分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接

评论区

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

目录