【发布时间】:2021-04-18 04:20:43
【问题描述】:
我想为 SVG 路径设置动画。我有相同的贝塞尔设置。当我将 2 个点移动到矩形中心时,动画跳动且不流畅。
我发现如果这些点最初不是在直线路径上,那么动画是平滑的!它看起来像一个错误(
请查看以下演示问题的代码或在jsfiddle查看它
<p>
Jumpy animation
</p>
<svg
width="200px"
height="133px"
viewBox="0 0 200 133"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
>
<path fill="#FFFFFF" stroke="#616161" stroke-width="4">
<animate
repeatCount="indefinite"
fill="freeze"
attributeName="d"
dur="1s"
values="
M194.002061,2 L6.04008364,2 C4.93732761,2 3.93634261,2.44884122 3.21071297,3.17293744 C2.4868279,3.89529278 2.03648273,4.89249429 2.03520721,5.99450035 C2.03520685,5.99479332 2.00668933,27.8652779 2.0009858,56.2997166 L2.00099044,75.7284095 C2.00633859,102.416639 2.03165325,123.946234 2.03537152,126.995569 C2.03658483,128.103158 2.48473311,129.104131 3.20922748,129.828298 C3.93400562,130.552748 4.93501692,131 6.04008364,131 L194.002061,131 C195.103988,131 196.103728,130.551165 196.827984,129.826994 C197.551106,129.103958 198,128.10572 198,127.002769 L198,6.00648893 C198,4.90021634 197.552004,3.89812727 196.827599,3.1726896 C196.10443,2.44849045 195.105573,2 194.002061,2 Z;
M194.002061,2 L6.04008364,2 C5.10902172,2 4.31668949,2.30236194 3.85350371,2.90851535 C3.39667486,3.50634969 3.31057704,4.33560556 3.54696163,5.22117815 C3.86947297,6.28159062 12,33.3316693 12,66 C12,98.5769844 3.88123574,126.502941 3.52148092,127.724391 C3.29190054,128.632682 3.3847554,129.480677 3.85171612,130.090231 C4.31671586,130.697225 5.10716799,131 6.04008364,131 L194.002061,131 C194.93514,131 195.729297,130.695801 196.194861,130.088316 C196.654,129.489213 196.743593,128.658124 196.508976,127.7702 C196.191061,126.712841 188,99.1556305 188,66 C188,32.9864348 196.081953,6.47466459 196.47066,5.21865408 C196.704535,4.32673476 196.625248,3.49294113 196.169159,2.8935357 C195.712562,2.29346354 194.928003,2 194.002061,2 Z;
"
/>
</path>
</svg>
<p>Smooth animation</p>
<svg
width="200px"
height="133px"
viewBox="0 0 200 133"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
>
<path fill="#FFFFFF" stroke="#616161" stroke-width="4">
<animate
repeatCount="indefinite"
fill="freeze"
attributeName="d"
dur="1s"
values="
M194.002061,2 L6.04008364,2 C5.01864027,2 4.13094436,2.38711966 3.54504923,3.05900142 C2.96245482,3.72709805 2.69875705,4.65340158 2.8319904,5.66241724 C2.94868384,6.43004297 7,33.3049889 7,66 C7,98.6124871 2.94857998,126.406308 2.81356562,127.323487 C2.6863776,128.338493 2.95459365,129.271195 3.54304738,129.943133 C4.13015485,130.613535 5.01675297,131 6.04008364,131 L194.002061,131 C195.024357,131 195.913135,130.612952 196.500141,129.941232 C197.083085,129.274159 197.347862,128.349268 197.215493,127.34166 C197.098926,126.569179 193,99.1791137 193,66 C193,32.9505546 197.046245,6.61163817 197.194423,5.65815893 C197.326276,4.64771432 197.066516,3.7189792 196.484282,3.05011469 C195.903212,2.38258626 195.021469,2 194.002061,2 Z;
M194.002061,2 L6.04008364,2 C5.10902172,2 4.31668949,2.30236194 3.85350371,2.90851535 C3.39667486,3.50634969 3.31057704,4.33560556 3.54696163,5.22117815 C3.86947297,6.28159062 12,33.3316693 12,66 C12,98.5769844 3.88123574,126.502941 3.52148092,127.724391 C3.29190054,128.632682 3.3847554,129.480677 3.85171612,130.090231 C4.31671586,130.697225 5.10716799,131 6.04008364,131 L194.002061,131 C194.93514,131 195.729297,130.695801 196.194861,130.088316 C196.654,129.489213 196.743593,128.658124 196.508976,127.7702 C196.191061,126.712841 188,99.1556305 188,66 C188,32.9864348 196.081953,6.47466459 196.47066,5.21865408 C196.704535,4.32673476 196.625248,3.49294113 196.169159,2.8935357 C195.712562,2.29346354 194.928003,2 194.002061,2 Z;
"
/>
</path>
</svg>
<p>How to create smooth animation that starts at the same point as the first rectangle? </p>
【问题讨论】:
-
要获得流畅的动画,您必须拥有相同数量的路径命令。它们也必须是相同类型的相同顺序。我想你的路径根本不够相似。 (路径命令是字母)。
-
我通过复制相同的形状并仅移动 2 个点来创建该路径。可能在从图形软件导出路径形状时,它会自动从路径中间移除 2 个点。在那种情况下,我认为没有办法让动画变得流畅。