使用Velocity.js变形不起作用

Morphing with Velocity.js doesnt work

本文关键字:不起作用 变形 js Velocity 使用      更新时间:2023-09-26

Hej,

我有一个plunker:http://plnkr.co/edit/bKzi6rU3lIXT4Nz2wkR8?p=info

    <!DOCTYPE html>
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" type="text/css" href="stilovi/main.css">
  <title>Testing</title>
</head>
<body>
  <div id="avengers"></div>
</body>
<script src="snap.svg-min.js"></script>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://rawgit.com/julianshapiro/velocity/master/velocity.min.js"></script>
<script>
  function fetchXML(url, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.onreadystatechange = function(evt) {
      //Do not explicitly handle errors, those should be
      //visible via console output in the browser.
      if (xhr.readyState === 4) {
        callback(xhr.responseXML);
      }
    };
    xhr.send(null);
  };
  /*var list = ["test3.svg","test.2svg"];*/
  //fetch the document
  fetchXML("test3.svg", function(newSVGDoc) {
    //import it into the current DOM
    var n = document.importNode(newSVGDoc.documentElement, true);
    document.getElementById("avengers").appendChild(n);
    var ironman = document.getElementsByTagName("polygon");
    var ironmanlist = Array.prototype.slice.call(ironman);
    /*alert(ironmanlist.length);*/
    ironmanlist.forEach(function(elem, i) {
      /*for (var index = 0; index < elem.points.length; ++index){
                    //2.test case morphing each point (not working)//
                    console.log(elem.points[index]);
                    $.Velocity(elem.points[index],{x:100,y:100},{duration:Math.floor(Math.random() * (3000 - 1000 + 1)) + 1000}, "ease-in-out");
                    //3.test case morphing each point in another way (not working)//
                    /*$(elem.points[index])
                        .velocity({x:100,y:100},{duration:Math.floor(Math.random() * (3000 - 1000 + 1)) + 1000}, "ease-in-out");
                    console.log(elem.points[index]);
                }*/
      //1. working test case (translation)//
      console.log(elem.points[0].x);
      $.Velocity(elem, {
        translateX: -300
      }, {
        duration: Math.floor(Math.random() * (3000 - 1000 + 1)) + 1000
      }, "ease-in-out");
      //$.Velocity(elem,{rotateZ:"45deg"},{duration:Math.floor(Math.random() * (3000 - 1000 + 1)) + 1000}, "ease-in-out");
      console.log(elem.points[0].x);
      //End of 1. working test case//
    });
    console.log(ironmanlist);

  });
</script>
</html>

用我的代码和一些例子。我想做的是将一个SVG图像中的每个多边形变形为另一个SVG图片中的另一个多边形。翻译是有效的,但我不知道如何变形。有人能帮忙吗?或者检查代码,告诉我我做错了什么?有很多多边形,我需要它很快,所以我用了velocity.js。

我也在考虑也许把它全部移到three.js,也许把它转换成一种最好与three.jss一起使用的格式。但如果有可能把它用作svg并保持良好的性能,我会这么做。

据我所知,velocity.js不支持这一点,因为(取自他们的网站):

通常,"速度"可以设置任何采用单个数值的特性的动画。

由于SVG路径通常(总是?)由多个值组成,因此变形远远超出了它们当前的范围。

但是,我强烈建议使用Snap来变形SVG路径。