Skip to content

Instantly share code, notes, and snippets.

@ojacobson
Created October 8, 2013 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ojacobson/6878082 to your computer and use it in GitHub Desktop.
Save ojacobson/6878082 to your computer and use it in GitHub Desktop.
function screenToSvg(svg, x, y) {
var point = svg.createSVGPoint();
point.x = x;
point.y = y;
var screenMatrix = svg.getScreenCTM();
var svgMatrix = screenMatrix.inverse();
return point.matrixTransform(svgMatrix);
}
$('svg').on('click', function(event) {
var svgPoint = screenToSvg(this, event.clientX, event.clientY);
console.log("Event:", event, "SVG point: ", svgPoint);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment