HTMLElement: offsetTop プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
offsetTop

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support