Har*_*hal 7 html5 svg google-chrome
在Chrome 48中,删除了PathSegList.当我读到另一个问题" 替代已弃用的SVG pathSegList "的答案时,Chrome正在提供一个新的API,但我想这个新的API尚不可用.什么是另一种选择,我该如何使用它.我知道这是重复的,但我提到的链接并没有帮助我.
您不需要路径段polyfill (pathSeg.js)。
使用路径数据 polyfill,您可以将路径数据作为通用数组对象进行编辑。
使用路径数据填充来使用新的 API。推荐。
var path = document.querySelector('path'); //your <path> element
//Be sure you have added the pathdata polyfill to your page before use getPathData
var pathdata = path.getPathData();
console.log(pathdata);
/*
you will get an Array object contains all path data details
like this:
[
{ "type": "M", "values": [ 50, 50 ] },
{ "type": "L", "values": [ 200, 200 ] }
]
*/
//replacement for createSVGPathSegMovetoRel and appendItem
pathdata.push({ type: 'm', values: [200, 100] });
path.setPathData(pathdata);
//replacement for createSVGPathSegMovetoAbs and appendItem
pathdata.push({ type: 'M', values: [300, 120] });
path.setPathData(pathdata);
//replacement for createSVGPathSegLinetoAbs and appendItem
pathdata.push({ type: 'L', values: [400, 120] });
path.setPathData(pathdata);
console.log(path.getAttribute('d'));
//create a new path data array
var pathdata = [
{ "type": "M", "values": [50, 50] },
{ "type": "L", "values": [200, 200] }
];
path.setPathData(pathdata);
console.log(path.getAttribute('d'));
Run Code Online (Sandbox Code Playgroud)