Hereif (el instanceof SVGElement)
The intention should be a capability test, but I found that the incoming element el, whether there is SVGElement on its prototype chain and whether it has getBoundingClientRect seems to have nothing to do with it. Relationship, right? Even if there is no SVGElement in the prototype chain of an element, it still has the getBoundingClientRect method. So what does the writing here mean?
me.getRect = function(el) {
if (el instanceof SVGElement) {
var rect = el.getBoundingClientRect();
return {
top : rect.top,
left : rect.left,
width : rect.width,
height : rect.height
};
} else {
return {
top : el.offsetTop,
left : el.offsetLeft,
width : el.offsetWidth,
height : el.offsetHeight
};
}
};
grateful!
CRIMX
Well-founded and convincing!
SVGElement - The properties offsetParent, offsetTop, offsetLeft, offsetWidth, and offsetHeight are deprecated in Chrome 48.
The offsetLeft and offsetTop properties of SVG elements always returns 'undefined'.
is not used for HTMLElement may be due to the fact that
getBoundingClientRect
is slower.