SVGAnimatedLength:animVal 属性

animVal 属性是 SVGAnimatedLength 接口的属性,它包含 SVG 枚举的当前值。如果没有动画,它与 baseVal 的值相同。

包含枚举当前值的 SVGLength

示例

html
<svg
  xmlns="http://www.w3.org/2000/svg"
  viewBox="0 0 100 100"
  width="200"
  height="200">
  <circle cx="50" cy="50" r="20" fill="gold" id="circle">
    <animate
      attributeName="r"
      values="20;25;10;20"
      dur="8s"
      repeatCount="indefinite" />
  </circle>
</svg>
<pre id="log"></pre>
js
const circle = document.getElementById("circle");
const log = document.getElementById("log");

function displayLog() {
  const animValue = circle.r.animVal.value;
  const baseValue = circle.r.baseVal.value;
  log.textContent = `The 'circle.r.animVal' is ${animValue}.\n`;
  log.textContent += `The 'circle.r.baseVal' is ${baseValue}.`;
  requestAnimationFrame(displayLog);
}
displayLog();

规范

规范
可缩放矢量图形 (SVG) 2
# __svg__SVGAnimatedLength__animVal

浏览器兼容性

BCD 表格仅在浏览器中加载

另请参阅