【发布时间】:2017-12-03 12:24:09
【问题描述】:
请告诉我,如何同步 svg 动画。生长线和动圈。我希望圆圈始终位于最前面。
body {
background-image: radial-gradient(circle farthest-corner at center, #1c262b 0, #000 100%)
}
#example {
height: 90vh;
display: block;
margin: 5vh auto;
}
.st0 {
fill: none;
stroke: #e2080c;
stroke-miterlimit: 10;
stroke-width: 1;
}
#rightCircle {
animation: animationRightCircle 2s linear;
animation-fill-mode: forwards;
}
@keyframes animationRightCircle {
0% {
transform: translate(320px, 2px)
}
33.33% {
transform: translate(638px, 2px)
}
66.66% {
transform: translate(638px, 638px)
}
100% {
transform: translate(320px, 638px)
}
}
#rightPath {
stroke-dasharray: 1276;
animation: pathGrowing 2s linear;
animation-fill-mode: forwards;
}
@keyframes pathGrowing {
0% {
stroke-dashoffset: 1276;
}
100% {
stroke-dashoffset: 0;
}
}
<svg id="example" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 640 640">
<path id="rightPath" class="st0" d="M320,1 639,1 639,639 320,639"/>
<defs>
<circle id="myCircle" r="2" fill="#e2080c"/>
</defs>
<use id="rightCircle" xlink:href="#myCircle" />
</svg>
我不明白为什么这些动画的速度不同。我试图延迟动画,但没有帮助
【问题讨论】: