[Web APIs] 브라우저 좌표 - Element.getBoundingClientRect()

2021. 6. 28. 18:10프로그래밍/웹관련

반응형

💡 Element.getBoundingClientRect()

Element의 위치와 크기 등의 정보를 알고 싶을 때!

MDN  요소의 크기와 뷰포트에 상대적인 위치에 대한 정보를 제공하는 DOMRect 개체를 반환.

 

주의 💦

CSS는 오른쪽 아래를 기준으로 bottom, right 이 측정되기 때문에 주의할 것!

 

Syntax

domRect = element.getBoundingClientRect();

 

 

참고

https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect

반응형