0

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...

user3142695
  • 15,844
  • 47
  • 176
  • 332
  • Use `getBoundingClientRect()` instead. – Asons Feb 21 '16 at 18:40
  • Possible duplicate of [Finding Offset Position of SVG Element](http://stackoverflow.com/questions/13040685/finding-offset-position-of-svg-element) – Asons Feb 21 '16 at 18:41

0 Answers0