This is how I'm calculating the correct position of an element, which should work also for scrolled position.
var element = $('#target');
console.log(getPosition(element));
getPosition = function (element) {
var xPosition = 0;
var yPosition = 0;
while (element) {
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
element = element.offsetParent;
}
return { x: xPosition, y: yPosition };
};
But I get the error 'SVGElement.offsetLeft' is deprecated and will be removed in M50, around April 2016. See https://www.chromestatus.com/features/5724912467574784 for more details.
It seems to me that I used offsetXY
in a wrong way...