offset
actually doesn't translate directly into layer
; the offset
property doesn't account for the element's margin. The code below should account for this.
function(e) {
var x = e.offsetX, y = e.offsetY;
if(e.hasOwnProperty('layerX')) {
x = e.layerX - e.currentTarget.offsetLeft;
y = e.layerY - e.currentTarget.offsetTop;
}
}