2009-11-12 97 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' 
); 

通常有更好的方法,不涉及尝试阅读样式表。

相关问题