Не работает свойство getBoundingClientRect, скажите почему?
<!DOCTYPE html>
<html>
<body>
<p id='aut'>AUT</p>
<script>
let aut = document.querySelector('#aut')
alert(aut.getBoundingClientRect());
</script>
</body>
</html>
Ответы (2 шт):
Автор решения: Vadim
→ Ссылка
Попробуй вывести так:
let aut = document.querySelector('#aut');
let {left, top, right, bottom, x, y, width, height} = aut.getBoundingClientRect();
console.log(left, top, right, bottom, x, y, width, height);
Все свойства описаны здесь, в возвращаемых значениях
Автор решения: CoderMotive
→ Ссылка
let aut = document.querySelector('#aut');
function showRect(elem) {
let r = elem.getBoundingClientRect();
alert(`x:${r.x}
y:${r.y}
width:${r.width}
height:${r.height}
top:${r.top}
bottom:${r.bottom}
left:${r.left}
right:${r.right}
`);
}
showRect(aut);