메서드는 엘리먼트(Element)의 크기와 뷰포트(Viewport)에 상대적인 위치 정보를 제공
다시 말해,
getBoundingClientRect() 의 요소의 위치는 고정값이 아니라 문서가 브라우저에서 스크롤 될 때 마다 값 전달.
console.log('offsetTop: ' + elem.offsetTop); //This is fixed. it get's calculated from beginning of your page to actual element's position.
console.log('getBoundingClientRect: ' + elem.getBoundingClientRect().top); // this will changing while scroll, because it's relative to your current view port.
참조 자료
https://developer.mozilla.org/ko/docs/Web/API/Element/getBoundingClientRect
'UI > Javascript' 카테고리의 다른 글
[indexof] => true & false (0) | 2023.12.16 |
---|---|
[agrument]변수 값으로 true/false 값 저장하기 (0) | 2023.12.13 |
[addEventListener]클릭 대상의 부모를 클릭해도 작동한다. (0) | 2023.12.05 |
[JavaScript]scrollTo를 통해서 움직이는 화면 이동 (0) | 2023.11.30 |
Framework and Library (0) | 2023.11.22 |