Skip to content

Instantly share code, notes, and snippets.

@stefanRepac
Created July 31, 2019 10:55
Show Gist options
  • Select an option

  • Save stefanRepac/4f526c7608cea53a101e120768117fe8 to your computer and use it in GitHub Desktop.

Select an option

Save stefanRepac/4f526c7608cea53a101e120768117fe8 to your computer and use it in GitHub Desktop.
Convert SVG path to SVG x,y cordinate to HTML coordinates
// 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