문서의 기하학적 특성
요소들의 크기와 위치 학습
getBoundingClientRect
엘리먼트의 크기와 위치를 알아내기 위한 API
body와 선택한 엘리먼트 사이의 길이만을
x : 선택요소의 x좌표
y : 선택요소의 y좌표
widht : 선택요소의 가로 길이
height : 선택요소의 세로 길이
top, left, right, bottom : 선택요소와 body태그 사이 길이(position: static인 부모의 자식은 )
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
.box {
width: 300px;
height: 300px;
padding: 20px;
margin: 20px;
border: 50px solid blue;
}
</style>
</head>
<body>
<div class="box">Coding</div>
<script>
console.log(document.querySelector('.box').getBoundingClientRect());
</script>
</body>
clientWidth, clientHeight : 테두리를 제외한 가로 세로 길이
Last updated
Was this helpful?