CSSOM视图模式getBoundingClientRect方法实例页面
回到相关文章 »代码:
HTML代码:
<button id="button1">返回本按钮距离文档左上角的上下左右值</button>
JS代码:
document.getElementById("button1").onclick = function() { var objRect = this.getBoundingClientRect(); alert("top:" + objRect.top + ", right:" + objRect.right + ", bottom:" + objRect.bottom + ", left:" + objRect.left); };