在 chrome 48 中被移除:SVGPathElement.pathSegList
本页 W3C 编辑草案 2016 年 1 月 19 日 显示访问段列表的新方法 https://svgwg.org/specs/paths/#InterfaceSVGPathData
但是,如何使用它呢? (在 SVGPathElement 中,“getPathData”方法不存在)
最佳答案
Chrome 尚未实现新的 getPathData 和 setPathData API。
你应该使用 path data polyfill :
https://github.com/jarek-foksa/path-data-polyfill.js
这是一个代码示例:
//svg code:
//...
//<path d="M0,0 L100,50" id="mypath"></path>
//<script xlink:href="/js/path-data-polyfill.js"></script>
//...
//js code:
var path = document.getElementById('mypath');
var pathdata = path.getPathData();
console.log(pathdata);
console.log(pathdata.length); //2
console.log(pathdata[0].type); //"M"
console.log(pathdata[0].values); //[0,0]
console.log(pathdata[1].type); //"L"
console.log(pathdata[1].values); //[100,50]
pathdata.push({type: "C", values: [100,-50,200,150,200,50]}); //add path segment
path.setPathData(pathdata); //set new path data
console.log(path.getAttribute('d')); //"M0,0 L100,50 C100,-50,200,150,200,50"
关于javascript - SVGPathData Chrome 48,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34919405/