动画没有按照预期的轨迹运动
来源:3-6 d3 入门

慕前端9304100
2023-10-26
目前的整体效果图
老师您好,期望是左上方1的图标按照2的红色轨迹运动,
在没有添加animateMotion动画前位置如1和2的正确位置,但添加之后轨迹跑到位置3进行运动了
这是什么原因造成的?该如何改造呢?
源码如下:
<template>
<div class="wr-print-box">
<svg width="100%" height="100%" viewBox="0 0 100 200">
<defs>
<linearGradient id="print-box-linear-graident">
<stop offset="0%" stop-color="#1E44B3"></stop>
<stop offset="100%" stop-color="#00B5FF"></stop>
</linearGradient>
</defs>
<g>
<path d="M32 40 L37 40 L37 45 L32 45 Z" fill="none" stroke="#808080" stroke-width="0.5" ></path>
<path d="M33.5 40.5 L35.5 40.5" fill="none" stroke="#ffffff" stroke-width="1" ></path>
<path d="M33.5 44.5 L35.5 44.5" fill="none" stroke="#ffffff" stroke-width="1" ></path>
<path d="M32 41 L37 41 L37 44 L32 44 Z" stroke-width="0.5" fill="url(#print-box-linear-graident)" ></path>
</g>
<g>
<path d="M32 40 L37 40 L37 45 L32 45 Z" fill="none" stroke="#808080" stroke-width="0.5" ></path>
<path d="M33.5 40.5 L35.5 40.5" fill="none" stroke="#ffffff" stroke-width="1" ></path>
<path d="M33.5 44.5 L35.5 44.5" fill="none" stroke="#ffffff" stroke-width="1" ></path>
<path d="M32 41 L37 41 L37 44 L32 44 Z" stroke-width="0.5" fill="url(#print-box-linear-graident)" ></path>
<animateMotion
dur="1s"
path="M32 40 L60 40 "
rotate="auto"
fill="freeze"
repeatCount="indefinite"
/>
</g>
<path d="M32 40 L61 40" fill="none" stroke="red" stroke-width="0.5"></path>
</svg>
</div>
</template>
写回答
1回答
-
扬_灵
2023-10-29
同学你好,这是animateMotion属性导致的,animateMotion中的path决定了方块走动的位置,你可以参考看一下下面这篇文档 http://www.javashuo.com/article/p-wmkdejcn-ew.html ,或者修改path属性为参考代码试下
<g> <path d="M32 40 L37 40 L37 45 L32 45 Z" fill="none" stroke="#808080" stroke-width="0.5" ></path> <path d="M33.5 40.5 L35.5 40.5" fill="none" stroke="#ffffff" stroke-width="1" ></path> <path d="M33.5 44.5 L35.5 44.5" fill="none" stroke="#ffffff" stroke-width="1" ></path> <path d="M32 41 L37 41 L37 44 L32 44 Z" stroke-width="0.5" fill="url(#print-box-linear-graident)" ></path> <animateMotion dur="3s" path="M0 0 H 10 40" rotate="auto" fill="freeze" repeatCount="indefinite" /> </g>
00
相似问题