How to replace the deprecated "svgElement.offsetWidth/height" on Chrome How to replace the deprecated "svgElement.offsetWidth/height" on Chrome google-chrome google-chrome

How to replace the deprecated "svgElement.offsetWidth/height" on Chrome


One way would be to remove to transform for all ancestors, calcualte the client rect, and then restore the transform of the ancestors:

function getOffsetWidth(elm) {  var cur, i;  var saveTransforms = [];  i = 0;  cur = elm;  //set the transform to '' for all ancestors  while (cur) {    if (cur.style) {      saveTransforms[i] = cur.style.transform;      cur.style.transform = '';    }    i++;    cur = cur.parentNode;  }  var rect = e.getBoundingClientRect();  i = 0;  cur = elm;  //restore the transform for all ancestors  while (cur) {    if (cur.style) {      cur.style.transform = saveTransforms[i];    }    i++;    cur = cur.parentNode;  }  return rect.width;}

Here the updated jsfiddle