如何加速 SVG 变形

问题描述

我正在为一家商店构建一个过滤菜单,我正在使用 svg 变形来为一些 svg 设置动画,当 getElementById 访问 svg 时效果很好,但在循环中一切都会受到性能影响。 这是我的js:

var iconNodes = document.querySelectorAll(".button-filter");
    

iconNodes.forEach(item => {
  item.addEventListener('click',event => {
    if (item.classList.contains("open")) {
      item.classList.remove("open");
      item.getElementsByClassName('anim-up')[0].beginElement();
      item.getElementsByClassName("button-text")[0].innerHTML = "Open";
    } else {
      item.classList.add("open");
      item.getElementsByClassName('anim-down')[0].beginElement();
      item.getElementsByClassName("button-text")[0].innerHTML = "Close";
    }
  })
});

和 html:

<button type="button" class="button-filter">
    <div class=""><span class="button-text">discount</span>
        <svg id="dropdown" viewBox="0 0 194.6 185.1" class="inline-block w-10 h-10">
            <polygon fill="#A2A7AA" points="53.4,65.1 96.6,65.1 75,90.1 75,90.1">
                <animate class="anim-up" begin="indefinite" fill="freeze" attributeName="points" dur="500ms" to="75,90.1 53.4,90.1"/>
                <animate class="anim-down" begin="indefinite" fill="freeze" attributeName="points" dur="500ms" to="53.4,90.1"/>
            </polygon>
        </svg>
    </div>
</button>

我该如何改变我的方法

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)