【问题标题】:2 different SVG path animations animate in the wrong way2 种不同的 SVG 路径动画以错误的方式制作动画
【发布时间】:2015-11-26 07:47:04
【问题描述】:

不久前我开始使用 SVG,我无法理解为什么它的工作方式不同。我有几个 SVG,我正在尝试将一个塑造成另一个。在这个例子中(我刚刚取出了困扰我的代码)我有 2 个路径对象移动到同一个位置。但一个只是出现和消失,而另一个则沿着路径移动。

我想实现如下对象的移动动画。点数有问题吗?因为我尝试了一个添加“虚拟点”(具有相同数量的更多点)以匹配点数的示例,但仍然发生同样的事情。 任何人都可以帮助我理解为什么会发生这种情况,也许可以阐明我做错了什么? 下面是代码示例:

HTML:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0" y="0" viewBox="0 0 363 356" xml:space="preserve" enable-background="new 0 0 363 356">
<g id="hi_orb_orange">
<linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="149.73" y1="104.66" x2="214.4" y2="104.66" gradientTransform="matrix(1.0526 0.3685 -0.3877 1.1076 9.673 -66.0063)">
  <animate attributeName="x1" values="149.73;227.736" dur="3s" repeatCount="indefinite" />
  <animate attributeName="y1" values="104.66;283.898" dur="3s" repeatCount="indefinite" />
  <animate attributeName="x2" values="214.4;301.366" dur="3s" repeatCount="indefinite" />
  <animate attributeName="y2" values="104.66;283.898" dur="3s" repeatCount="indefinite" />
  <stop offset="0.04" class="s7"/>
  <stop offset="1" class="s8"/>
</linearGradient>
<path class="st1" d="M194.8 128.9c-4.2 12-22.8 16.3-41.6 9.7 -18.8-6.6-30.6-21.6-26.5-33.6s22.8-16.3 41.6-9.7C187.1 101.9 199 117 194.8 128.9z">

<animate attributeName="d" values="M194.8 128.9c-4.2 12-22.8 16.3-41.6 9.7 -18.8-6.6-30.6-21.6-26.5-33.6s22.8-16.3 41.6-9.7C187.1 101.9 199 117 194.8 128.9z;
M274.3 193.9c-5.8 16.5-23.5 18.8-40.9 12.8 -17.4-6.1-37.4-37.7-31.6-54.2 5.8-16.5 19.6-17.1 37-11C256.2 147.6 280.1 177.4 274.3 193.9z;
M194.8 128.9c-4.2 12-22.8 16.3-41.6 9.7 -18.8-6.6-30.6-21.6-26.5-33.6s22.8-16.3 41.6-9.7C187.1 101.9 199 117 194.8 128.9z" dur="3s" repeatCount="indefinite"/>

</path>
<linearGradient id="SVGID_3_" gradientUnits="userSpaceOnUse" x1="88.44" y1="-61.73" x2="153.12" y2="-61.73" gradientTransform="matrix(1.0526 -0.3685 -0.3877 -1.1076 9.673 199.3584)">
  <animate attributeName="x1" values="88.44;227.736;88.44" dur="3s" repeatCount="indefinite" />
  <animate attributeName="y1" values="-61.73;283.898;-61.73" dur="3s" repeatCount="indefinite" />
  <animate attributeName="x2" values="153.12;301.366;153.12" dur="3s" repeatCount="indefinite" />
  <animate attributeName="y2" values="-61.73;283.898;-61.73" dur="3s" repeatCount="indefinite" />
  <stop offset="0.04" class="s7"/>
  <stop offset="1" class="s8"/>
</linearGradient>
<path class="st2" d="M194.8 211.3c-4.2-12-22.8-16.3-41.6-9.7 -18.8 6.6-30.6 21.6-26.5 33.6 4.2 12 22.8 16.3 41.6 9.7C187.1 238.3 199 223.3 194.8 211.3z">

<animate attributeName="d" values="M194.8 211.3c-4.2-12-22.8-16.3-41.6-9.7 -18.8 6.6-30.6 21.6-26.5 33.6 4.2 12 22.8 16.3 41.6 9.7C187.1 238.3 199 223.3 194.8 211.3z;
M274.3 193.9c-5.8 16.5-23.5 18.8-40.9 12.8 -17.4-6.1-37.4-37.7-31.6-54.2 5.8-16.5 19.6-17.1 37-11C256.2 147.6 280.1 177.4 274.3 193.9z;
M194.8 211.3c-4.2-12-22.8-16.3-41.6-9.7 -18.8 6.6-30.6 21.6-26.5 33.6 4.2 12 22.8 16.3 41.6 9.7C187.1 238.3 199 223.3 194.8 211.3z" dur="3s" repeatCount="indefinite"/>

</path>
</g>
</svg>

这是小提琴...https://jsfiddle.net/16syyazs/

【问题讨论】:

  • 欢迎来到 Stackoverflow。能否请您添加一个小提琴,以便我们为您提供帮助?
  • 嘿,在解释中添加了小提琴。

标签: html xml svg path jquery-animate


【解决方案1】:

为了流畅地制作动画(即插值),所有动画都必须包含相同数量和类型的动画。

<animate attributeName="d" values="
M194.8 128.9c-4.2 12  -22.8 16.3-41.6 9.7  -18.8-6.6-30.6-21.6-26.5-33.6s22.8-16.3 41.6-9.7C187.1 101.9 199 117 194.8 128.9z;
M274.3 193.9c-5.8 16.5-23.5 18.8-40.9 12.8 -17.4-6.1-37.4-37.7-31.6-54.2 5.8-16.5 19.6-17.1 37-11C256.2 147.6 280.1 177.4 274.3 193.9z;
M194.8 128.9c-4.2 12  -22.8 16.3-41.6 9.7  -18.8-6.6-30.6-21.6-26.5-33.6s22.8-16.3 41.6-9.7C187.1 101.9 199 117 194.8 128.9z" dur="3s" repeatCount="indefinite"/>

如果我将上面的动画排列起来,我可以看到顶部和底部的值有一个 s,但中间的没有。可能还有其他类似的问题。

【讨论】:

  • 那么问题。解决这个问题的正确方法是什么?可以说绘制 1 个对象。将其保存为 SVG,然后将对象更改为对象编号 2。将其保存为 SVG,然后将动画应用于第一个动画以动画到第二个?当然,留下相同的数量和相同的积分顺序?
  • 我注意到了,是的。第二行有一个 S,缺少 3 个点。解决这个问题的最佳方法是什么?制作新的 SVG 形状并注意点/曲线的数量和顺序?或者有什么办法我可以简单地更改代码以某种方式对齐它?
  • 解决这个问题的最佳/唯一方法是让它们都一样。如何做到这一点取决于您。
猜你喜欢
  • 2015-04-10
  • 2016-02-14
  • 2016-01-06
  • 2020-10-14
  • 1970-01-01
  • 2022-01-03
  • 1970-01-01
  • 1970-01-01
  • 2021-08-16
相关资源
最近更新 更多