Last active
August 29, 2015 14:10
-
-
Save rurabe/a16d0a096ef59b3c0956 to your computer and use it in GitHub Desktop.
A jQuery extension that reports the locations of clicks in the SVG coordinate system
This file contains 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
(function(){ | |
var transform = function(el,pt){ | |
return pt.matrixTransform( el.getScreenCTM().inverse() ); | |
}; | |
$.fn.extend({ | |
reportLocations : function(callback){ | |
var $this = this; | |
var svg = $this.closest('svg')[0]; | |
var pt = svg.createSVGPoint(); | |
var el = $this[0]; | |
this.on("click",function(e){ | |
pt.x = e.clientX; pt.y = e.clientY; | |
var transformedPt = pt.matrixTransform( el.getScreenCTM().inverse() ); | |
callback.call($this,e,transformedPt) | |
}); | |
} | |
}); | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment