javascript - 使用 anime.js 变形 : coordinates jump somewhere else in between given start and end position

标签 javascript css svg anime.js

我有两个 svg 三 Angular 形,我正在尝试使用 anime.js 对它们进行变形。我遇到的问题是,在给定的开始和结束坐标之间,图形完全跳到其他地方,我不知道为什么。

这是开始位置:

enter image description here

这是结束位置:

enter image description here

这就是坐标在不知不觉中跳转到的地方:

enter image description here

这是我的示例代码。您可以通过单击按钮启动它。

https://codepen.io/saitam1/pen/draKLb

最佳答案

问题出在你的路径上。

为了使动画不粗暴地改变三 Angular 形的位置,当您的第一个路径使用绝对坐标 M 时,路径必须使用相对坐标 m

m 更改为 M 修复了三 Angular 形跳跃,但您必须找到另一条路径才能真正到达所需的最终位置。

function doFunction() {

  var paths = [
    // here changed M to m
    {id: '#path309', d: 'm 55.184523,127.42857 34.962798,139.6183 43.46726,120.24702 Z'}, 
    {id: '#path311', d: 'm 54.389347,121.02185 -10.922087,-0.77483 11.717263,7.18155 z'}
  ];

  var timeline = anime.timeline({ autoplay: true, direction: 'alternate', loop: false });

  paths.forEach(function(path, index) {
    timeline
      .add({
        targets: path.id,
        d: {
          value: path.d,
          duration: 1000,
          easing: 'easeInOutQuad'
        },
        offset: 1000 + 10 * index
      });
  });

}
svg {
  display: block;
  margin: 0 auto;
}

path {
  fill: none;
  stroke: black;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.2.0/anime.min.js"></script>
<input id="clickMe" type="button" value="clickme" onclick="doFunction();" />  

<svg xmlns="http://www.w3.org/2000/svg" width="100mm" height="100mm" viewBox="0 0 200 200">
      
  <path d="m 110.51595,80.797791 26.28083,12.271789 2.96257,10.935445 z" id="path309" />
  <path d="m 70.51595,80.797791 -5.00762,25.058566 11.28845,-2.786777 z" id="path311" />
      
</svg>

关于javascript - 使用 anime.js 变形 : coordinates jump somewhere else in between given start and end position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55324346/

相关文章:

css - Firefox 是否支持 css 掩码?

javascript - 根据输入 Jquery 中的 keyup 确定第 n 个类型

javascript - 如何将选择选项插入对象数组中

javascript - 将本地存储中的元素添加到 html 下拉菜单的建议

html - 如何删除按钮周围的框?

javascript - SVG 文本边缘未正确对齐

javascript - 使用 javascript 在选择列表中选择的下一个日期

javascript - 如何将窗口对象从事件选项卡发送到扩展?

javascript - 大尺寸图像在 jcrop 中无法正确裁剪

r - 将 networkD3 图形导出为矢量图形