.getRelativeBox()
Available on: InDomReturns a DOMRect with coordinates relative to the underlying element’s offset parent (borders of the parent are excluded).Returns: {DOMRect} - Native object with left / x, top / y, width, height, right, bottom.Throws:
Error - If the underlying element has been removed
Error - If the underlying element is not connected to the document
Examples:const div = $n('<div></div>');
div.setStyle({
display: 'inline-block',
position: 'fixed',
top: '110px',
left: '130px',
width: '100px',
height: '150px',
backgroundColor: 'blue'
});
$1('body').append(div);
console.log(JSON.stringify(div.getBox()));
//DOMRect {"x":130,"y":110,"width":100,"height":150,"top":110,"right":230,
//"bottom":260,"left":130}
const innerDiv = $n('<div></div>');
innerDiv.setStyle({
display: 'inline-block',
position: 'absolute',
top: '10px',
left: '30px',
width: '30px',
height: '50px',
backgroundColor: 'red'
});
div.append(innerDiv);
console.log(JSON.stringify(innerDiv.getRelativeBox()));
//DOMRect {"x":30,"y":10,"width":30,"height":50,"top":10,"right":60,
//"bottom":60,"left":30}
// red innerDiv: positioned inside blue div; coords are relative to blue’s padding boxNext: getOffsetBox »