2016-02-01 16 views
5

Chrome 48では、PathSegListが削除されました。もう1つの質問Alternative for deprecated SVG pathSegListの回答を読むと、Chromeは新しいAPIを提供していますが、この新しいAPIはまだ使用できません。もう1つの選択肢は何ですか?どのように使用できますか?私はこれが重複していることを知っていますが、私が言及したリンクは私を助けていません。ChromeでPathSegListが廃止され、削除されました。48

+0

リンクされた回答の1つに記載されているポリフィルはなぜ役に立ちませんか? –

+0

今では、私のアプリケーションにpoly-data-polyfill.jsを追加しました。しかし、SVGPathSeg.PATHSEG_MOVETO_REL、createSVGPathSegMovetoAbs、および他の同様の定数やAPIを置き換えるものは何ですか? – Harshal

+0

ポリフィルは置換を定義します。 https://github.com/progers/pathseg/blob/master/pathseg.js#L20 –

答えて

2

path seg polyfill(pathSeg.js)は必要ありません。

path data polyfillを使用すると、共通のアレイオブジェクトとしてパスデータを編集できます。

path data 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')); 
関連する問題