Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save stefanRepac/ac73cc2c9ac5ee9e55cc51659527d4f5 to your computer and use it in GitHub Desktop.
Convert SVG <rect> x,y cordinate to HTML cordinate
// Convert SVG <rect> x,y cordinate to HTML cordinate
var svg = this;
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 = svg.attr('x');
point.y = svg.attr('y');
position = point.matrixTransform(matrix);
el.style.left = position['x'] + 'px';
el.style.top = position['y'] + 'px';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment