offsetLeft、offsetTop全面解析
一、第一个小例子
<body>
<style>
body {
margin:0; }
.box1 {
width:300px; height:300px; margin:100px; background:#333; overflow:hidden; }
.box2 {
width:200px; height:200px; margin:100px; background:#666; overflow:hidden; }
.box3 {
width:100px; height:100px; margin:100px; background:#999;}
</style>
<div class="box1">
<div class="box2">
<div class="box3"></div>
</div>
</div>
<script>
var oBox1 = document.querySelector('.box1');
var oBox2 = document.querySelector('.box2');
var oBox3 = document.querySelector('.box3');
console.log('box1: '+ oBox1.offsetLeft +','+ oBox1.offsetTop);
console.log('box2: '+ oBox2.offsetLeft +','+ oBox2.offsetTop);
console.log('box3: '+ oBox3.offsetLeft +','+ oBox3