duration="2s" 不适用于动画 svg 元素

duration="2s" does not work on animating a svg element

我正在尝试为 svg 元素制作动画。当我将 duration 设置为 1s 并根据它写入 keyTimes 时,它起作用了。但是当我将持续时间跨度到 2s 时,它会以某种方式中断。

这是有效的代码:

<rect id="Rectangle-8-Copy-4" fill="#D7E0E7" x="10" y="10" width="46" height="4">
    <animate attributeName="fill" begin="0s" dur="1s" keyTimes="0;0.50;1" repeatCount="indefinite" values="#D7E0E7;#879CAD;#EBF0F3"/>
</rect>

https://jsfiddle.net/s3958psq/1/

当我将持续时间更改为两秒时,它停止了动画:

<rect id="Rectangle-8-Copy-4" fill="#D7E0E7" x="10" y="10" width="46" height="4">
    <animate attributeName="fill" begin="0s" dur="2s" keyTimes="0;1;2" repeatCount="indefinite" values="#D7E0E7;#879CAD;#EBF0F3"/>
</rect>

https://jsfiddle.net/s3958psq/

我真的很想知道这里发生了什么。

当您更改持续时间时,您不得更改 keyTimes。它们总是介于 0(开始)和 1(结束)之间。

超出范围 0..1 的值无效并导致动画被忽略。

<svg width="83px" height="114px" viewBox="0 0 83 114">
    <title>Group 23 Copy 3</title>
    <desc>Created with Sketch.</desc>
    <defs>
        <path d="M41.5,1.99808051 C41.5,0.894571116 40.6135756,0 39.4919018,0 L4.15,0 C1.8592,0 0,1.824 0,4.07142857 L0,109.928571 C0,112.176 1.8592,114 4.15,114 L78.85,114 C81.1408,114 83,112.176 83,109.928571 L83,42.7110903 C83,41.6082856 82.1024789,40.7142857 80.9907068,40.7142857 L43.575,40.7142857 C42.427525,40.7142857 41.5,39.8043214 41.5,38.6785714 L41.5,1.99808051 Z M47.7922479,2.10168901 C46.6091171,0.940958221 45.65,1.34759596 45.65,2.99863879 L45.65,33.6442184 C45.65,35.3003208 47.0013718,36.6428571 48.6433707,36.6428571 L80.0066293,36.6428571 C81.6598223,36.6428571 82.0392027,35.7002505 80.8577521,34.5411681 L47.7922479,2.10168901 Z" id="path-1"></path>
        <mask id="mask-2" maskContentUnits="userSpaceOnUse" maskUnits="objectBoundingBox" x="0" y="0" width="83" height="114" fill="white">
            <use xlink:href="#path-1"></use>
        </mask>
    </defs>
    <rect fill="#D7E0E7" x="10" y="10" width="46" height="4">
        <animate attributeName="fill" begin="0s" dur="2s" keyTimes="0;0.5;1" repeatCount="indefinite" values="#D7E0E7;#879CAD;#EBF0F3"/>
    </rect>
</svg>