offsetParent //获取给了定位元素的父级
offsetLeft //返回元素的相对定位父元素水平偏移位置。 返回number
offsetTop //返回元素的相对定位父元素水平垂直偏移位置。
offsetWidth //返回元素的宽度 — 包含width,padding,border
offsetHeight //返回元素的高度
<style>#parent{position: relative;height: 200px;width: 200px;background: yellow;}#test{position: absolute;width: 100px;height: 100px;background: red;top:20px;left: 100px;padding: 20px;border:10px solid #333;}</style><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); //100console.log(test.offsetTop) //20console.log(test.offsetWidth) //160</script>
