HTML:標記語言
CSS:樣式語言
JavaScript:指令碼語言
Web API:程式設計介面
所有 Web 技術
學習 Web 開發
發現我們的工具
更好地瞭解 MDN
此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 2015 年 7 月以來,各瀏覽器均已提供此特性。
HTMLElement 介面的只讀屬性 offsetTop 返回當前元素的外部邊框(包括其外邊距)到 offsetParent 的頂部內邊距邊緣的距離,即最近的已定位的祖先元素。
HTMLElement
offsetTop
offsetParent
一個數字。
const d = document.getElementById("div1"); const topPos = d.offsetTop; if (topPos > 10) { // object offset is more // than 10 pixels from its parent }
載入中…
Element.clientTop
Element.scrollTop
HTMLElement.offsetHeight
HTMLElement.offsetWidth
HTMLElement.offsetLeft
Element.getBoundingClientRect()