This seems like an amazing question, but there is ALMOST duplicate here: How to get MouseEvent coordinates for an element with CSS3 Transform? but no one is looking at my answer there, and that seems a lot more general, so I will post it again here, with a few changes, to make it more clear:
Basically, it works by doing this: divide the element by which you are trying to find the relative coordinates, and divide it into 9 smaller elements. Use document.elementFromPoint to find out if the coordinate is above this mini element. If so, divide this element into another 9 elements and continue to do so until the coordinates are sufficiently accurate. Then use getBoundingClientRect to find the screen coordinates of this widget. BOOM!
jsfiddle: http://jsfiddle.net/markasoftware/rA27K/8/
Here is the JavaScript function:
function convertPointFromPageToNode(elt,coords){
IMPORTANT!!! You must also include this CSS to work:
.offsetrect{ position: absolute; opacity: 0; height: 33.333%; width: 33.333%; } #topleftoffset{ top: 0; left: 0; } #topcenteroffset{ top: 0; left: 33.333%; } #toprightoffset{ top: 0; left: 66.666%; } #centerleftoffset{ top: 33.333%; left: 0; } #centercenteroffset{ top: 33.333%; left: 33.333%; } #centerrightoffset{ top: 33.333%; left: 66.666%; } #bottomleftoffset{ top: 66.666%; left: 0; } #bottomcenteroffset{ top: 66.666%; left: 33.333%; } #bottomrightoffset{ top: 66.666%; left: 66.666%; }
ALSO: I changed your css a bit by providing a βgrandfatherβ div id and referencing it in your css using #div1 instead of div because my code generates a div and your div styles also applied to the ones my code uses, and ruined it.
ONE LAST THING: I don't know CoffeeScript, so I adjusted your code to make it pure JavaScript. Excuse me.
source share