CSS100Day(24)-一个按钮动画

625 字
3 分钟
CSS100Day(24)-一个按钮动画

设计简介#

关键点如下

  1. 知识点1:使用svg的 dasharray 需要知道期望的周长,然后设置实线和虚线

  2. 知识点2:注意使用动画时候,利用动画时间和延迟事件来完成整个动画

效果展示#

实现代码和步骤#

HTML部分#

<div class="frame">
<input type="checkbox" id="button" class="hidden" />
<label for="button" class="button">
Finish
<img src="https://100dayscss.com/codepen/checkmark-green.svg" />
</label>
<svg class="circle">
<circle cx="30" cy="30" r="29" />
</svg>
</div>

CSS部分#

.frame {
width: 400px;
height: 400px;
color: #fff;
background: #57d895;
box-shadow: 1px 2px 10px 0 rgba(0, 0, 0, 0.3);
position: relative;
}
.hidden {
display: none;
}
.button {
position: absolute;
box-sizing: border-box;
display: block;
width: 260px;
height: 60px;
top: 170px;
left: 70px;
border-radius: 30px;
border: 2px solid #fff;
text-align: center;
line-height: 56px;
font-size: 20px;
font-weight: 700;
letter-spacing: 2px;
cursor: pointer;
text-transform: uppercase;
transition: all 0.3s ease-in-out;
&:hover {
background: #37be77;
}
img {
position: absolute;
top: 16px;
left: 15px;
opacity: 0;
z-index: 2;
}
}
.circle {
position: absolute;
width: 60px;
height: 60px;
z-index: 2;
top: 170px;
left: 170px;
fill: none;
stroke: #fff;
stroke-width: 2px;
stroke-linecap: round;
stroke-dasharray: 183 183;
stroke-dashoffset: 183;
pointer-events: none;
transform: rotate(-90deg);
}
input:checked {
& ~ .button {
animation:
button 0.5s ease both,
fill 0.5s ease-out 1.5s forwards;
img {
animation: check 0.5s ease-out 1.5s both;
}
}
& ~ .circle {
animation: circle 2s ease-out 0.5s both;
}
}
@keyframes button {
0% {
width: 260px;
left: 70px;
border-color: #fff;
color: #fff;
}
50% {
color: transparent;
}
100% {
width: 60px;
left: 170px;
border-color: #45b078;
background: transparent;
color: transparent;
}
}
@keyframes fill {
0% {
background: transparent;
border-color: #fff;
}
100% {
background: #fff;
}
}
@keyframes check {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes circle {
0% {
stroke-dashoffset: 183;
}
50% {
stroke-dashoffset: 0;
stroke-dasharray: 183;
opacity: 1;
transform: rotate(-90deg) scale(1);
}
100% {
opacity: 0;
transform: rotate(-90deg) scale(2);
stroke-dashoffset: 0;
}
}
分享给其他人
如果该文章对您有帮助,欢迎分享给其他人阅读!
复制链接

评论区

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

目录