animation - 如何反转 <mpath> 上 SVG 动画的移动方向?

标签 animation svg smil

http://codepen.io/KeliChiu/pen/gabNWM 嗨,我正在尝试反转 SMIL SVG 动画中两个红点沿路径的移动方向。对于我从文档中获得的所有属性,我无法找到适合此尝试的属性。帮助表示赞赏! 文档在这里: http://www.w3.org/TR/SVG/animate.html#AnimateMotionElement

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="320px"
         height="320px" viewBox="0 0 320 320" enable-background="new 0 0 320 320" xml:space="preserve">

                <path class="stage1" id="stage1-1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="
                M160,220.499c-11.284,0-20.432-9.147-20.432-20.432v-40.868"/>

                <path class="stage1" id="stage1-2" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="
                M180.432,159.199v40.868c0,11.284-9.147,20.432-20.432,20.432"/>

  <circle  r="8" fill="red">
  <animateMotion dur=".6s" begin=".4s" fill="remove" rotate="auto" >
       <mpath xlink:href="#stage1-1"/>
    </animateMotion>
</circle>
<circle r="8" fill="red">
  <animateMotion dur=".6s" begin="s" fill="remove" rotate="auto">
       <mpath xlink:href="#stage1-2"/>
    </animateMotion>
</circle>
    </svg>

最佳答案

最简单的方法是使用keyTimeskeyPoints 属性告诉动画向后运行。

keyPoints="1;0" keyTimes="0;1"

这里我们告诉动画在时间 0 时位于路径上的位置“1”(结束),在动画结束时位于位置 0(开始)。

演示:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" 
     width="320px" height="320px" viewBox="0 0 320 320">

    <path class="stage1" id="stage1-1" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="M160,220.499c-11.284,0-20.432-9.147-20.432-20.432v-40.868"/>
    <path class="stage1" id="stage1-2" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" d="M180.432,159.199v40.868c0,11.284-9.147,20.432-20.432,20.432"/>

    <circle  r="8" fill="red">
        <animateMotion dur=".6s" begin=".4s" fill="remove" rotate="auto"
                       keyPoints="1;0" keyTimes="0;1" calcMode="linear">
            <mpath xlink:href="#stage1-1"/>
        </animateMotion>
    </circle>
    <circle r="8" fill="red">
        <animateMotion dur=".6s" begin=".4s" fill="remove" rotate="auto"
                       keyPoints="1;0" keyTimes="0;1" calcMode="linear">
            <mpath xlink:href="#stage1-2"/>
        </animateMotion>
    </circle>
</svg>

关于animation - 如何反转 <mpath> 上 SVG 动画的移动方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32423332/

相关文章:

html - 每次重复的 SVG 动画延迟

javascript - svg 动画从动态值转换

ios - 如何在小游戏中正确复用UIView?

javascript - jQuery 动画数字计数器从零到值 - 当值达到数十万时计数器显示错误值

javascript - 如何让 slider 在 JavaScript 中滑动时显示信息?

javascript - 加载到 div 后使用 snap 为 SVG 制作动画

javascript - 使用 SMIL 的 SVG 动画

ios - 通过更改宽度和高度来动画矩形

react-native - 如何在 native react 中添加对 Animated.sequence 的函数调用

安卓 : automate SVG import