关键点

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流浏览器均已支持。

keyPoints 属性指示动画的简单持续时间。

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

示例

html
<svg
  viewBox="0 0 120 120"
  xmlns="http://www.w3.org/2000/svg"
  xmlns:xlink="http://www.w3.org/1999/xlink">
  <path
    d="M10,110 A120,120 -45 0,1 110 10 A120,120 -45 0,1 10,110"
    stroke="lightgrey"
    stroke-width="2"
    fill="none"
    id="motionPath" />
  <circle cx="10" cy="110" r="3" fill="lightgrey" />
  <circle cx="110" cy="10" r="3" fill="lightgrey" />

  <circle r="5" fill="red">
    <animateMotion
      dur="3s"
      repeatCount="indefinite"
      keyPoints="0;0.5;1"
      keyTimes="0;0.15;1"
      calcMode="linear">
      <mpath href="#motionPath" />
    </animateMotion>
  </circle>
</svg>

用法说明

<number> [; <number> ]* ;?
默认值 None
可动画的
<number> [; <number>] ;?

此值定义了一个由浮点值组成的、以分号分隔的列表,这些值介于 0 和 1 之间,并指示对象在由相应 keyTimes 值指定的时间点上沿着运动路径移动的距离。距离是沿着由 path 属性指定的路径计算的。列表中的每个进度值对应于 keyTimes 属性列表中的一个值。

如果指定了关键点列表,则 keyPoints 列表中的值数量必须与 keyTimes 列表中的值数量完全相同。

如果值末尾有分号,后面可选地跟着空格,则分号和尾随的空格都会被忽略。

如果值规范中存在任何错误(例如,无效值,值过多或过少),则这是一个错误。

规范

规范
SVG 动画级别 2
# KeyPointsAttribute

浏览器兼容性