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 GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
offsetTop |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.