offsetParent //获取给了定位元素的父级
    offsetLeft //返回元素的相对定位父元素水平偏移位置。 返回number
    offsetTop //返回元素的相对定位父元素水平垂直偏移位置。
    offsetWidth //返回元素的宽度 — 包含width,padding,border
    offsetHeight //返回元素的高度

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