Created
August 31, 2017 08:13
-
-
Save negativo/c1dc4afbf55d51ecfe0d71f944a1c1ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// svg | |
<svg class="elephant"> | |
<g transform="scale(3)"> | |
<polygon id="Page-1" points="23.3328895 11.1580892 22.8418363 11.1580892 16.0917836 17.9081419 12.9359147 14.7522731 12.4448616 14.7522731 9.95540651 17.224721 9.95540651 17.7157742 15.8467128 23.60708 16.337766 23.60708 25.8053725 14.1394735 25.8053725 13.6484203"></polygon> | |
</g> | |
</svg> | |
// js | |
var polys = document.querySelectorAll('polygon,polyline'); | |
[].forEach.call(polys,convertPolyToPath); | |
function convertPolyToPath(poly){ | |
var svgNS = poly.ownerSVGElement.namespaceURI; | |
var path = document.createElementNS(svgNS,'path'); | |
var points = poly.getAttribute('points').split(/\s+|,/); | |
var x0=points.shift(), y0=points.shift(); | |
var pathdata = 'M'+x0+','+y0+'L'+points.join(' '); | |
if (poly.tagName=='polygon') pathdata+='z'; | |
path.setAttribute('d',pathdata); | |
poly.parentNode.replaceChild(path,poly); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment