【发布时间】:2016-05-17 20:09:45
【问题描述】:
我的代码在这里显示复选标记的动画。
它可以工作,但问题是,它不会循环。它只动画 1 次。我想要的是每 2 秒为它制作一次动画。
Codepen 链接:http://codepen.io/haniotis/pen/KwvYLO
CSS 看起来像这样:
@import "bourbon";
$color--green: #7ac142;
$curve: cubic-bezier(0.650, 0.000, 0.450, 1.000);
.checkmark__circle {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: $color--green;
fill: none;
animation: stroke .6s $curve forwards;
}
.checkmark {
width: 56px;
height: 56px;
border-radius: 50%;
display: block;
stroke-width: 2;
stroke: #fff;
stroke-miterlimit: 10;
margin: 10% auto;
box-shadow: inset 0px 0px 0px $color--green;
animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark__check {
transform-origin: 50% 50%;
stroke-dasharray: 48;
stroke-dashoffset: 48;
animation: stroke .3s $curve .8s forwards;
}
@keyframes stroke {
100% {
stroke-dashoffset: 0;
}
}
@keyframes scale {
0%, 100% {
transform: none;
}
50% {
transform: scale3d(1.1, 1.1, 1);
}
}
@keyframes fill {
100% {
box-shadow: inset 0px 0px 0px 30px $color--green;
}
}
HTML 看起来像这样:
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
<circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none" />
<path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8" />
</svg>
【问题讨论】:
-
使动画无限很容易,您只需将迭代次数设置为无限。每 2 秒重复一次需要对关键帧进行一些更改,如提到的 here。
-
对于您的情况,它比这要复杂一些,因为您有 3 个动画,并且每个动画都必须进行调整,以便在开始下一个循环之前让其他动画完成。
标签: css svg css-animations