2009-11-12 98 views

回答

0

offsetTop返回設置爲position:relative;position:absolute;集合的樹中位於較低節點的頂部偏移量。

您是否將父母的職位設置爲相對絕對

0

嘗試

element.style.top 
3

offsetTop獲取頁面(相對於offsetParent,這是任何定位元件或偶爾一些其他類型的元件的)的像素作爲編號的元件的位置。

style.top得到top財產的style="top: 500px"內聯字符串值的屬性只

如果你想獲得已從樣式表設置top樣式值,則不能使用style.top這將直接返回''告訴你top沒有在style屬性被設置。取而代之的是由DOM Level 2 Style定義的window.getComputedStyle,以及由IE使用的element.currentStyle。 (較舊的瀏覽器也不支持)

var top= (window.getComputedStyle? 
    window.getComputedStyle(element, null).getPropertyValue('top') : 
    element.currentStyle? element.currentStyle.top : '0' 
); 

通常有更好的方法,不涉及嘗試閱讀樣式表。

相關問題