我如何通过 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)
}
答案 0 :(得分:3)
您可以获取路径的片段(创建路径时输入的位置/坐标):
var numberOfItems = myPath.node.pathSegList.numberOfItems; // handy for loops
var firstCoordinate = myPath.node.pathSegList.getItem(0);
console.log firstCoordinate.x;
console.log firstCoordinate.y;