Mat*_*att 2 html svg easing svg-animate
我尝试向元素添加keySplines, values, keyTimes属性animate来模拟缓动动画。缓和效果不起作用。
HTML
<svg xmlns="http://www.w3.org/2000/svg" id="arrow-slider-1" viewBox="0 0 766 22" width="766" height="22" fill="black" stroke="black">
<path d="M765 22 765 15 L39 15 L25 0 L11 15 L0.5 15 L0.5 21.5 Z">
<animate class="triangle-animation" attributeType="XML" attributeName="d" from="M765 22 765 15 L39 15 L25 0 L11 15 L0.5 15 L0.5 21.5 Z" to="M765,22L765,15L505.00002429484215,15L490.00002429484215,0L475.00002429484215,15L0.5,15L0.5,21.5" dur="4s" repeatCount="1" fill="freeze" keySplines=" 0.1 0.8 0.2 1; 0.1 0.8 0.2 1; 0.1 0.8 0.2 1; 0.1 0.8 0.2 1; 0.1 0.8 0.2 1; 0.1 0.8 0.2 1" keyTimes="0;0.22;0.33;0.55;0.66;0.88;1" calcMode="spline" begin="indefinite"></animate>
</path>
</svg>
<button id="btn">Click me</button>
Run Code Online (Sandbox Code Playgroud)
JS
document.getElementById("btn").onclick = function(e) {
console.log('anim');
document.querySelector('.triangle-animation').beginElement();
}
Run Code Online (Sandbox Code Playgroud)
keyTimes,则必须提供一个values包含匹配数量的分号分隔条目的列表,或者如果使用fromand to,则keyTimes必须"0;1"并且keySplines必须仅包含一个条目。Z命令,则每个值都需要一个。例外:可以使用或省略可选的命令字母(用于重复相同的命令)。begin="btn.click"。<svg xmlns="http://www.w3.org/2000/svg" id="arrow-slider-1" viewBox="0 0 766 22" width="766" height="22" fill="black" stroke="black">
<path d="M765 22 765 15 L39 15 L25 0 L11 15 L0.5 15 L0.5 21.5 Z">
<animate class="triangle-animation" attributeType="XML" attributeName="d" values="
M765 22 765 15 L39 15 L25 0 L11 15 L0.5 15 L0.5 21.5 Z;
M765 22 765 15 239 15 225 0 211 15 L0.5 15 L0.5 21.5 Z;
M765 22 765 15 505 15 L490 0 L475 15 L0.5 15 L0.5 21.5 Z"
keySplines="0.1 0.8 0.2 1;0.1 0.8 0.2 1"
keyTimes="0;0.5;1"
dur="4s" repeatCount="1" fill="freeze" calcMode="spline" begin="btn.click"></animate>
</path>
</svg>
<button id="btn">Click me</button>Run Code Online (Sandbox Code Playgroud)