javascript - 使用 Snap.svg 带有箭头标记的动画路径

标签 javascript svg snap.svg svg-animate

我正在研究如何为末端带有箭头标记的路径设置动画。我正在尝试对对 Angular 线进行动画处理。

您可以在此处查看正在运行的示例:http://codepen.io/danieltnaves/pen/ZWryxm

var animationsPaths = new Array();
animationsPaths.push("M 100 10 L 200 110");
animationsPaths.push("M 100 10 L 230 110");
animationsPaths.push("M 250 110 L 300 10");
animationsPaths.push("M 400 110 L 600 210");
animationsPaths.push("M 700 210 L 800 10");
animationsPaths.push("M 700 210 L 850 110");

var paper = Snap("#paper");

function animatePaths() {
   if (animationsPaths.length == 0) return;
   var line2 = paper.path(animationsPaths[0]);
   var lengthLine2 = line2.getTotalLength();
   console.log(animationsPaths);
   animationsPaths.shift();

   var Triangle = paper.polyline("0,10 5,0 10,10");
   Triangle.attr({
     fill: "#000"
   });  

   var triangleGroup = paper.g( Triangle ); // Group polyline

   Snap.animate(0, lengthLine2 - 1, function( value ) {
      movePoint = line2.getPointAtLength( value );
      triangleGroup.transform( 't' + parseInt(movePoint.x - 15) + ',' +     parseInt(movePoint.y - 15) + 'r' + (movePoint.alpha - 90));
   }, 500,mina.easeinout);


line2.attr({
   stroke: '#000',
   strokeWidth: 2,
   fill: 'none', 
   // Draw Path
   "stroke-dasharray": lengthLine2 + " " + lengthLine2,
   "stroke-dashoffset": lengthLine2
    }).animate({"stroke-dashoffset": 20}, 500, mina.easeinout, animatePaths.bind( this ));
   }

   animatePaths();

谢谢!

最佳答案

我首先将三 Angular 形居中,然后事情会变得更容易......

var Triangle = paper.polyline("-5,5 0,-5 5,5");

http://codepen.io/anon/pen/PNQXbQ

关于javascript - 使用 Snap.svg 带有箭头标记的动画路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36572084/

相关文章:

javascript - 关闭时更改动画哦汉堡包图标

javascript - 使用 <svg> 的正确方法

javascript - Snap.svg 纸张对象

javascript - 在 d3 中从 v3 转换为 v5 不会更新可视化,但会添加另一个可视化

javascript - 使用 html javascript 处理目录中的文件

javascript - 将鼠标悬停在其父 div 上时,如何更改链接为对象的 SVG 的属性?

html - 如何使用:before to add <use> for <svg> tags?

svg - 如何应用 SVG 滤镜来创建整个轮廓的彩色 SVG 形式?

javascript - SVG 尺寸在悬停时永久改变

javascript - 在Vue js中将数据从父组件传递到子组件的子组件