2

如何 访问和枚举控制点及其在svg/snapsvg路径中​​的坐标?

就像是:

 var myPath = s.path("M 18,0 4.5,9 13.5,9 9,18 0,36 18,36 36,0 z");

 myPath.attr("d").forEach(function(point)
 {
 console.log("x:"+point.x," y:"+point.y)
 }
4

1 回答 1

4

您可以像这样获取路径段(创建路径时输入的位置/坐标):

var numberOfItems = myPath.node.pathSegList.numberOfItems; // handy for loops
var firstCoordinate = myPath.node.pathSegList.getItem(0);
console.log firstCoordinate.x;
console.log firstCoordinate.y;
于 2014-01-07T10:18:43.460 回答