SVG animation start position

别等时光非礼了梦想. 提交于 2019-12-11 12:12:39

问题


i have a small SVG animation that i have been playing around with and i was wondering if there is a simple solution for the following issue.

Is there a way of changing the start point of where the circle starts? As it always seems to start on the right hand 3 o'clock position and goes around clockwise. Ideally i want it to start where and when the line finishes animating. Example: http://jsfiddle.net/matta70/7jvd6fsx/1/

 .line {
    stroke-dasharray: 650;
    stroke-dashoffset: 650;
    animation: offset 3s linear forwards;
 }
 .circle {
    stroke-dasharray: 230;
    stroke-dashoffset: 230;
    animation: offset 3s linear forwards;

 }


 /*========================
 *      KEYFRAMES
 */

 @keyframes offset {
    100% {
        stroke-dashoffset: 0;

    }
 }


<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="577px"
     height="74px" viewBox="0 0 577 74" enable-background="new 0 0 577 74" xml:space="preserve">
    <g id="Layer_1">
        <line class="line" fill="none" stroke="#000000" stroke-width="2" x1="0" y1="37" x2="504" y2="37"/>
        <circle class="circle" fill="none" stroke="#000000" stroke-width="2" cx="540" cy="37" r="36"/>
        <circle fill="none" stroke="#000000" stroke-width="2" cx="540" cy="37" r="18"/>
    </g>
</svg>

回答1:


You need to use

transform="rotate(<angle>)"

here a working code

<style>
 .line {
     stroke-dasharray: 650;
     stroke-dashoffset: 650;
     animation: offset 3s linear forwards;
 }
 .circle {
     stroke-dasharray: 230;
     stroke-dashoffset: 230;
     animation: offset 1s linear forwards 2.3s;
 }
 /*========================
     *      KEYFRAMES
     */
 @keyframes offset {
     100% {
         stroke-dashoffset: 0;
     }
 }
</style>
<body>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="577px" height="74px" viewBox="0 0 577 74" enable-background="new 0 0 577 74" xml:space="preserve">
<g id="Layer_1">
    <line class="line" fill="none" stroke="#000000" stroke-width="2" x1="0" y1="37" x2="504" y2="37" />
    <circle class="circle" transform="rotate(180 540 37)"  fill="none" stroke="#000000" stroke-width="2" cx="540" cy="37" r="36" />
    <circle fill="none" stroke="#000000" stroke-width="2" cx="540" cy="37" r="18" />
</g>

You can find a well explained tutorial here

Here there is a Jsfiddle copied from somewhere, time ago. (hove image)

Hope this help




回答2:


You can rotate the circle using ransform:rotate(180 ...), and delay the circle animation using animation-delay.

http://jsfiddle.net/6sp2fv2q/



来源:https://stackoverflow.com/questions/31775990/svg-animation-start-position

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!