HTMLElement: offsetTop 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

HTMLElement 介面的只讀屬性 offsetTop 返回當前元素的外部邊框(包括其外邊距)到 offsetParent 的頂部內邊距邊緣的距離,即最近的已定位的祖先元素。

一個數字。

示例

js
const d = document.getElementById("div1");
const topPos = d.offsetTop;

if (topPos > 10) {
  // object offset is more
  // than 10 pixels from its parent
}

規範

規範
CSSOM 檢視模組
# dom-htmlelement-offsettop

瀏覽器相容性

另見