![](/img/trans.png)
[英]How to find an html element x,y,width or height without visibly rendering an html string
[英]How to get X,Y width and height of all the links on an HTML page
我正在開發Google Chrome擴展程序,我想跟蹤特定頁面上所有錨點的位置(像素坐標)。 目前,我有以下代碼,該代碼遍歷頁面上的所有錨點。
function clickHandler(){
// BUG: print this anchors location
alert(this.top);
}
var anchors = document.getElementsByTagName("a");
i=anchors.length;
while (i--) {
anchors[i].addEventListener('click', clickHandler, false);
}
我應該如何獲取錨點的x,y坐標以及寬度和高度? 嘗試僅嘗試訪問錨點的top和left屬性的天真方法向我展示了它們是未定義的。
怎么樣offsetTop
, offsetLeft
, offsetWidth
, offsetHeight
。 您必須offsetParent
來解析絕對坐標。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.