offsetLeft和offsetTop大家看看我在控制台是undefined?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
body{
width: 200px;
height: 200px;
border: 20px solid #ccc;
margin: 10px;
padding: 20px;
overflow: scroll;
position: relative;
left: 150px;
top: 50px;
}
.mdiv{
width: 100px;
height: 100px;
border: 10px solid #ccc;
margin: 10px;
padding: 20px;
position: relative;
left: 150px;
top: 50px;
}
</style>
</head>
<body>
<div class="mdiv"></div>
<script type="text/javascript">
console.log(document.body.offsetHeight);
console.log(document.body.offsetWidth);
console.log(document.getElementsByClassName('mdiv').offsetLeft);
console.log(document.getElementsByClassName('mdiv').offsetTop);
</script>
</body>
</html>