简体   繁体   中英

svg file in html and i want to covert the javascript formate

i have one svg file in html and i want to get path front that file like

data:[-23.978,2.474,0,-18.691,2.474,0,-16.108,2.595,0,-14.207,2.866,0,-12.443,3.292,0,-11.003,3.793,0,-9.653,4.413,0,-8.741,4.929,0,-7.869,5.506,0,-6.341,6.686,0,-5.837]

Like this above format please help me.

you need like this?

 var x = document.getElementsByTagName("polygon")[0].getAttribute("points"); var x = document.getElementsByTagName("path")[0].getAttribute("d"); var obj = {}; obj['data'] = x.split(' '); console.log(obj); 
 <svg width="300" height="200"> <polygon points="100,10 40,198 190,78 10,78 160,198" style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" /> </svg> <svg widht:"100" height:"100"> <path d="M10 10 H 90 V 90 H 10 L 10 10"/> </svg> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM