Created
July 31, 2019 10:55
-
-
Save stefanRepac/4f526c7608cea53a101e120768117fe8 to your computer and use it in GitHub Desktop.
Convert SVG path to SVG x,y cordinate to HTML coordinates
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
| // Convert SVG path to HTML x,y cordinate | |
| // Length of path | |
| var pathLength = Math.floor( this.getTotalLength() ); | |
| prcnt = pathLength / 100; | |
| // Get x and y values at a certain point in the line | |
| pt = this.getPointAtLength(prcnt); | |
| pt.x = Math.round(pt.x); | |
| pt.y = Math.round(pt.y); | |
| var svg_el = document.getElementsByClassName(element_class); | |
| var rootSVG = document.querySelector("#front-view svg"); | |
| var point = rootSVG.createSVGPoint(); | |
| var matrix, position; | |
| matrix = svg_el[0].getCTM(); | |
| point.x = pt.x; | |
| point.y = pt.y; | |
| position = point.matrixTransform(matrix); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment