So, I thought a little about this problem, as the Chrome team wants to remove layerX and layerY for strange reasons.
First, we need the position of your container:
var position = $paper.offset();
(for those who read without a violin, $ paper is the div where the svg line will be displayed)
It gives us two coordinates, position.top
and position.left
, so we know where the container is on the page.
Then, when clicked, we use e.pageX
and e.pageY
, which are the coordinates of the page. To emulate layerX and layerY, we use (e.pageX - position.left)
and (e.pageY - position.top)
Et voilร : http://jsfiddle.net/GHZSd/30/
Powered by chrome, Safari, FF and Opera.
source share