offsetParent //获取给了定位元素的父级
    offsetLeft //返回元素的相对定位父元素水平偏移位置。 返回number
    offsetTop //返回元素的相对定位父元素水平垂直偏移位置。
    offsetWidth
    offsetHeight

    1. <style>
    2. #parent{
    3. position: relative;
    4. width:200px;
    5. height: 200px;
    6. background: yellow;
    7. }
    8. #test{
    9. position: absolute;
    10. width:100px;
    11. height: 100px;
    12. background: red;
    13. left:100px;
    14. top:10px;
    15. padding:20px;
    16. border:10px solid #333;
    17. }
    18. </style>
    19. </head>
    20. <body>
    21. <div id="parent">
    22. <div>
    23. <div id="test">hello world</div>
    24. </div>
    25. </div>
    26. <script>
    27. var test = document.getElementById("test");
    28. console.log(test.offsetParent)
    29. console.log(test.offsetLeft)
    30. console.log(test.offsetTop)
    31. console.log(test.offsetWidth)
    32. console.log(test.offsetHeight)
    33. </script>
    34. </body>
    1. ![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)