HTMLElement: offsetTop プロパティ

HTMLElement.offsetTop は読み取り専用プロパティで、現在の要素の外枠から、最も近い位置にある祖先要素である offsetParent の上枠の内側までの距離を相対的に返します。

数値です。

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

if (topPos > 10) {
  // 要素が offsetParent から 11px 以上離れている場合の処理をここに記述
}

仕様書

Specification
CSSOM View Module
# dom-htmlelement-offsettop

ブラウザーの互換性

BCD tables only load in the browser