--- title: HTMLElement.offsetTop slug: Web/API/HTMLElement/offsetTop translation_of: Web/API/HTMLElement/offsetTop ---
HTMLElement.offsetTop
повертає відстань від поточного елемента відносно верху {{domxref("HTMLelement.offsetParent","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 }
Специфіуація | Статус | Коментар |
---|---|---|
{{SpecName('CSSOM View', '#dom-htmlelement-offsettop', 'offsetTop')}} | {{Spec2('CSSOM View')}} |
{{Compat("api.HTMLElement.offsetTop")}}
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.)