요소의 left, top, width, height 값을 반환한다.
function myFunction() {
var div = document.getElementById("myDiv");
var rect = div.getBoundingClientRect();
x = rect.left;
y = rect.top;
w = rect.width;
h = rect.height;
alert ("Left: " + x + ", Top: " + y + ", Width: " + w + ", Height: " + h);
}
'javascript' 카테고리의 다른 글
익명함수 (0) | 2017.08.16 |
---|---|
Math 함수 (0) | 2017.08.16 |