0
var rect = document.getElementById("object").getBoundingClientRect();
console.log("rect.top, rect.right, rect.bottom, rect.left");

<div id="object"></div>

.object {
background: red;
width: 20px;
height: 20px;
position: relative;
top: 200px;
}

超级基本问题...我正在尝试获取#object的坐标,但控制台返回rect.top、rect.right、rect.bottom、rect.left,而不是#object的实际坐标。我错过了什么?

JSFiddle:http: //jsfiddle.net/tCraA/2/

4

1 回答 1

1

您已经记录了一个静态字符串:

console.log("rect.top, rect.right, rect.bottom, rect.left");

你的意思是这样写:

console.log(rect.top, rect.right, rect.bottom, rect.left);
于 2013-09-16T02:51:51.463 回答