CSS100Day(20)-发送邮件惊艳动画无JS

961 字
5 分钟
CSS100Day(20)-发送邮件惊艳动画无JS

设计简介#

用精美的动画效果给访客带来惊喜,而不是简单的“请求已发送”提示

  1. 知识点1:点击发送按钮可以使用checkbox:checked来执行效果,而不使用javascript点击事件

  2. 知识点2:前面学过使用stroke-dasharray,以及stroke-dashoffset对SVG线段做出绘画的感觉

效果展示#

实现代码和步骤#

HTML部分#

HTML部分如下,主要是实现邮件和纸飞机的svg,仅有svg有stroke系列属性

<div class="frame">
<input type="checkbox" id="cb" />
<label for="cb" class="button">发送邮件</label>
<label for="cb" class="button reset">重置</label>
<div class="circle"></div>
<div class="circle-outer"></div>
<svg class="icon mail">
<polyline points="119,1 119,69 1,69 1,1"></polyline>
<polyline points="119,1 60,45 1,1 119,1"></polyline>
</svg>
<svg class="icon plane">
<polyline points="119,1 1,59 106,80 119,1"></polyline>
<polyline points="119,1 40,67 43,105 69,73"></polyline>
</svg>
</div>

CSS部分#

.frame {
width: 400px;
height: 400px;
box-shadow: 1px 2px 10px 0 rgba(0, 0, 0, 0.3);
border-radius: 2px;
background: #2c3e50;
overflow: hidden;
position: relative;
}
.circle {
position: absolute;
background: #354a5f;
border-radius: 50%;
width: 200px;
height: 200px;
top: 65px;
left: 100px;
}
.circle-outer {
position: absolute;
box-sizing: border-box;
background: none;
border: 4px solid #354a5f;
border-radius: 50%;
width: 200px;
height: 200px;
top: 65px;
left: 100px;
}
.icon {
position: absolute;
z-index: 2;
top: 130px;
left: 140px;
transform: translate3d(0, 0, 0);
fill: none;
stroke-width: 2px;
stroke: #ecf0f1;
stroke-linecap: square;
stroke-dasharray: 325 325;
&.mail {
width: 120px;
height: 70px;
stroke-dashoffset: 0;
}
&.plane {
width: 120px;
height: 110px;
stroke-dashoffset: 325;
}
}
#cb {
display: none;
}
.button {
position: absolute;
z-index: 10;
top: 290px;
left: 100px;
background: #ecf0f1;
color: #2c3e50;
width: 200px;
height: 40px;
border-radius: 20px;
text-align: center;
line-height: 40px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 700;
&.reset {
opacity: 0;
z-index: 5;
}
&:hover {
background: #1abc9c;
color: #fff;
}
}
#cb:checked ~ .button {
animation: button 1.5s ease-in-out 1.7s;
animation-fill-mode: both;
}
#cb:checked ~ .reset {
animation: reset 1s ease-in-out 3.7s;
animation-fill-mode: both;
}
#cb:checked ~ .mail {
transition: stroke-dashoffset 1s ease-in-out;
stroke-dashoffset: 325;
}
#cb:checked ~ .plane {
transition: stroke-dashoffset 1s ease-in-out 0.6s;
stroke-dashoffset: 0;
animation: fly 2.4s ease-in-out;
animation-fill-mode: both;
}
#cb:checked ~ .circle {
animation: circle 1s ease-in-out;
animation-fill-mode: both;
}
#cb:checked ~ .circle-outer {
animation: circle 0.8s ease-in-out 0.2s;
animation-fill-mode: both;
}
@keyframes button {
0% {
transform: scale(1);
}
30% {
background: #1abc9c;
color: transparent;
width: 200px;
left: 100px;
}
50%,
60% {
width: 40px;
left: 180px;
transform: scale(1);
}
70% {
transform: scale(1.1);
}
100% {
width: 40px;
left: 180px;
background: #1abc9c;
color: transparent;
transform: scale(0);
}
}
@keyframes reset {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes fly {
0%,
50% {
transform: translate3d(0, 0, 0) scale(1);
}
60% {
transform: translate3d(-10px, 5px, 0) scale(1.05);
}
70% {
opacity: 1;
}
85% {
opacity: 0;
}
100% {
transform: translate3d(300px, -150px, 0) scale(0.5);
opacity: 0;
}
}
@keyframes circle {
0% {
transform: translate3d(0, 0, 0) scale(1);
}
20% {
transform: scale(1.1);
}
100% {
transform: scale(0);
}
}
分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接

评论区

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

目录