如果一个元素的position属性是absolute,那么使用getComputedStyle().left一定可以获得px的值。
但是如果不是, 那么得到的就是auto了。 即getComputedStyle并不是所有的时候都会得到数值
<style>
div{width:100px;height:100px;background-color: yellowgreen;position: absolute;}
</style>
<body>
<div>houdunren>/div>
<script>
let left = parseInt(window.getComputedStyle(div).left);
console.log(left) 结果为 8
</script>
<body>