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/