일반 getBoundingClientRect in FF3

황제낙엽 2013.01.11 18:16 조회 수 : 36

sitelink1  
sitelink2  
sitelink3  
sitelink4 http://1 
extra_vars4 ko 
extra_vars5 http://techbug.tistory.com/108 
extra_vars6 sitelink1 
IE5에서 첫선을 보인 객체.getBoundingClientRect는 객체의 offset의 top, left,width,height를 반환하는 멋진놈이다.
일반적으로 gecko 엔진을 사용하는 FF2에서는 getBoxObjectFor(객체)를 사용했으나
FF3에서는  getBoundingClientRect도 지원한다.

FF3가 출시되자 마자 기존 스크립트들을 많이 바꾸고 있는데 이중에 getBoundingClientRect가 포함되었다.
드디어 FF도 IE의 손을 들어준것인가? IE8에서는 얼마만큼 오픈소스진영의 손을 들어줄것인지 귀추가 주목된다.


bounding.png


데꾸벅이 사용하는 객체의 offset left,top,width, height반환하는 함수
/**
 * tag 객체의 위치값 및 너비/높이값을 반환한다.
 * @param {objId} DOM객체 : document.getElementById()
 * @return {ret} left,top,width,height 를 반환한다.
 * @author 데꾸벅
 */
function getBoundsObject(objId){
    var techbug = new Object();
    var tag = document.getElementById(objId);

    if(tag !=null && tag != undefined ){
        if(tag.getBoundingClientRect){ //IE, FF3 
            var rect = tag.getBoundingClientRect();
            techbug.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft);
            techbug.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop);
            techbug.width = rect.right - rect.left;
            techbug.height = rect.bottom - rect.top +1; // +1 = Moz와 맞춤
        } else  if (document.getBoxObjectFor) { // gecko 엔진 기반 FF3제외
            var box = document.getBoxObjectFor(tag);
            techbug.left = box.x;
            techbug.top = box.y;
            techbug.width = box.width;
            techbug.height = box.height;
        }else {
            techbug.left = tag.offsetLeft;
            techbug.top = tag.offsetTop;
            techbug.width = tag.offsetWidth;
            techbug.height = tag.offsetHeight  + 3;  // +1 = Moz와 맞춤
            var parent = tag.offsetParent;
            if (parent != tag) {
                while (parent) {
                    techbug.left += parent.offsetLeft;
                    techbug.top += parent.offsetTop;
                    parent = parent.offsetParent;
                }
            }
            // 오페라와 사파리의 'absolute' postion의 경우 body의 offsetTop을 잘못 계산 보정
            var ua = navigator.userAgent.toLowerCase();
            if (ua.indexOf('opera') != -1 || ( ua.indexOf('safari') != -1 && getStyle(tag, 'position') == 'absolute' )) {
                techbug.top -= document.body.offsetTop;
            }

        }
        return techbug;
    }
}


번호 제목 글쓴이 날짜 조회 수
177 익스플로러용 스크립트 디버거 (Script Debugger for Windows NT 4.0 and Later) 황제낙엽 2008.12.11 176
176 MS 익스플로러상에서 문제가 되는 Leak 모델 황제낙엽 2009.04.03 171
175 소스 보기 막기 황제낙엽 2005.11.18 168
174 문자열에서 역슬래시(backslash) 문자와 유니코드(Unicode)에 대한 고찰 file 황제낙엽 2021.06.03 160
173 [펌] 아사페릴의 사생활 - Javascript의 constructor 와 prototype 황제낙엽 2009.04.02 156
172 JAVASCRIPT REFERENCE 파일 file 황제낙엽 2005.11.22 153
171 CKEditor 3 JavaScript API Documentation 황제낙엽 2011.11.14 147
170 Java 버전의 JavaScript 엔진 라이노 (Rhino) 황제낙엽 2008.07.14 146
169 [JavaScript Tutorials] More leakage patterns (해석중) 황제낙엽 2009.04.10 142
168 CORS 의 내용과 이에 대한 우회 방안들 file 황제낙엽 2021.12.05 139
167 CORS(Cross-Origin Resource Sharing) - 1 file 황제낙엽 2017.03.07 135
166 재사용 가능한 일회용 객체 황제낙엽 2008.08.08 133
165 inherits() 를 이용한 상속 황제낙엽 2012.07.18 129
164 HTTP 접근 제어 (CORS) 황제낙엽 2017.05.29 125
163 call() and apply() methods in Javascript 황제낙엽 2011.10.07 125
162 외부 라이브러리 (.js) 의 바람직한 동적 로딩 (The best way to load external JavaScript) 황제낙엽 2009.10.05 124
161 자동 형변환 (문자열 -> 숫자) 황제낙엽 2009.06.25 124
160 자바스크립트 학습용 유튜브 강의 (드림코딩 by 엘리) 황제낙엽 2021.03.07 122
159 무지개링크 (rainbowlink) file 황제낙엽 2005.07.16 122
158 Rhino 와 env.js 를 사용해서 자바 서버에서 javascript 를 구동해보자 file 황제낙엽 2012.02.15 116