HTMLElement.offsetTop
Властивість лише для зчитування
HTMLElement.offsetTop
повертає відстань від поточного елемента відносно верху offsetParent
.Синтакс
topPos = element.offsetTop;
Параметри
topPos
це кількість пікселів від верху найближчого відносно зпозиціонованого батьківського елементу.
Приклад
var d = document.getElementById("div1");
var topPos = d.offsetTop;
if (topPos > 10) {
// object is offset more
// than 10 pixels from its parent
}
Специфікація
Специфіуація | Статус | Коментар |
---|---|---|
CSS Object Model (CSSOM) View Module The definition of 'offsetTop' in that specification. |
Working Draft |
Браузерна сумісність
BCD tables only load in the browser
In compliance with the specification, this property will return null
on Webkit if the element is hidden (the style.display
of this element or any ancestor is "none"
) or if the style.position
of the element itself is set to "fixed"
.
This property will return null
on Internet Explorer (9) if the style.position
of the element itself is set to "fixed"
. (Having display:none
does not affect this browser.)