Computer/JavaScript

화면상의 위치 가져오기

알찬돌삐 2012. 8. 10. 16:36

function getBounds(tag)
{
    var ret = new Object();
    if(document.all) {
        var rect = tag.getBoundingClientRect();
        ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft);
        ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop);
        ret.width = rect.right - rect.left;
        ret.height = rect.bottom - rect.top;
    } else {
        var box = document.getBoxObjectFor(tag);
        ret.left = box.x;
        ret.top = box.y;
        ret.width = box.width;
        ret.height = box.height;
    }
    return ret;
}


var box = getBounds(document.getElementById('youranytag'));
box.left
box.top
box.width
box.height

 

저작권자 - PHPSCHOOL 송효진

이 글은 스프링노트에서 작성되었습니다.

.

'Computer > JavaScript' 카테고리의 다른 글

chrome notification https 미지원  (0) 2018.02.14
폼 검사기  (0) 2012.08.10
키코드 표  (0) 2012.08.10
쿠키  (0) 2012.08.10
자동완성  (0) 2012.08.10