offsetParent //获取给了定位元素的父级
offsetLeft //返回元素的相对定位父元素水平偏移位置。 返回number
offsetTop //返回元素的相对定位父元素水平垂直偏移位置。
offsetWidth
offsetHeight
<style>
#parent{
position: relative;
width:200px;
height: 200px;
background: yellow;
}
#test{
position: absolute;
width:100px;
height: 100px;
background: red;
left:100px;
top:10px;
padding:20px;
border:10px solid #333;
}
</style>
</head>
<body>
<div id="parent">
<div>
<div id="test">hello world</div>
</div>
</div>
<script>
var test = document.getElementById("test");
console.log(test.offsetParent)
console.log(test.offsetLeft)
console.log(test.offsetTop)
console.log(test.offsetWidth)
console.log(test.offsetHeight)
</script>
</body>
![image.png](https://cdn.nlark.com/yuque/0/2019/png/446381/1567259125409-951f3a54-e5d9-4d1d-9b45-915e7ccf575d.png#align=left&display=inline&height=478&name=image.png&originHeight=478&originWidth=331&size=14537&status=done&width=331)