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()