关键样条

keySplines 属性定义了一组与 keyTimes 列表相关联的 贝塞尔曲线 控制点,定义了一个控制间隔节奏的三次贝塞尔函数。

除非将 calcMode 属性设置为 spline,否则将忽略此属性。

如果 keySplines 规范中存在任何错误(值无效、值过多或值过少),动画将不会发生。

你可以将此属性与以下 SVG 元素一起使用

示例

html
<svg viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
  <circle cx="60" cy="10" r="10">
    <animate
      attributeName="cx"
      dur="4s"
      calcMode="spline"
      repeatCount="indefinite"
      values="60; 110; 60; 10; 60"
      keyTimes="0; 0.25; 0.5; 0.75; 1"
      keySplines="0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1" />
    <animate
      attributeName="cy"
      dur="4s"
      calcMode="spline"
      repeatCount="indefinite"
      values="10; 60; 110; 60; 10"
      keyTimes="0; 0.25; 0.5; 0.75; 1"
      keySplines="0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1; 0.5 0 0.5 1" />
  </circle>
</svg>

用法说明

<control-point> [ ; <control-point> ]* ;?
默认值 None
可动画的

属性值是分号分隔的控制点描述列表。

<control-point>

每个控制点描述是一组四个值:x1 y1 x2 y2,用于描述一个时间段的贝塞尔控制点。定义相关时间段的 keyTimes 值是贝塞尔“锚点”,而 keySplines 值是控制点。因此,控制点集数必须比 keyTimes 少一个。

x1 y1 x2 y2 的值必须都在 0 到 1 的范围内。

Safari 问题

keyTimes 值应使用分号分隔,前面没有空格,例如:keyTimes="0; 0.25; 0.5; 0.75; 1"

规范

规范
SVG 动画级别 2
# KeySplinesAttribute

另见