• 회원가입
  • 로그인
  • 구글아이디로 로그인

[DOM_Element] JS - getBoundingClientRect() 메서드 - 뷰포트 기준 요소크기와 요소위치 반환 (= getBoundingClientRect메서드 = 겟바운딩클라이언트렉트메서드) (IE9 이상) ※ 요소 (너비/높이/위치) 구하기

getBoundingClientRect() 예제

 

<style>

.out {height:200px; width:300px; overflow:auto;}

 #hz {width:250px; height:150px; border:1px solid red;}

.in {width:750px ; height:1000px; background:yellow;}

</style>


<script>

function homzzang() {

  var div = document.getElementById("hz");

  var box = div.getBoundingClientRect();

  x = box.left;

  y = box.top;

  w = box.width;

  h = box.height;

  var res = "Left: " + x + ", Top: " + y + ", Width: " + w + ", Height: " + h;

  alert (res);

}

</script>


<div class="out">

    <div id="hz">홈짱닷컴 Homzzang.com</div>

    <div class="in"></div>

</div>


<button onclick="homzzang()">클릭</button>

 

결과보기

결과값: Left: 8, Top: 8, Width: 260, Height: 160

 


분류 제목
DOM_Event JS - inputType -
DOM_Event JS - isComposing -
DOM_Event JS - isTrusted -
DOM_Event JS - key 속성 -
DOM_Event JS - key 속성 -
DOM_Event JS - keyCode 속성 - 눌린 키보드키 유니코드 (= onkeypress, onkeydown, on…
DOM_Event JS - location -
DOM_Event JS - lengthComputable -
DOM_Event JS - loaded -
DOM_Event JS - metaKey -
DOM_Event JS - metaKey -
DOM_Event JS - MovementX -
DOM_Event JS - MovementY -
DOM_Event JS - newValue -
DOM_Event JS - newURL -
DOM_Event JS - offsetX 속성 - x좌표 (= 가로좌표 = 가로축좌표 = offsetX속성 = 오프셋엑스속성)
DOM_Event JS - offsetY 속성 - y좌표 (= 세로좌표 = 세로축좌표, offsetY속성, IE6)
DOM_Event JS - oldValue -
DOM_Event JS - oldURL -
DOM_Event JS - onemptied -
37/67
목록
찾아주셔서 감사합니다. Since 2012