<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
body{
width: 2000px;
height: 2000px;
}
div{
width: 200px;
height: 200px;
background: blue;
margin: 100px;
}
p{
width: 100px;
height: 100px;
margin: 30px;
background: red;
}
</style>
</head>
<body>
<div id="box">
<p></p>
</div>
<script>
// 打印事件对象
box.onclick = function(evt){
console.log(evt.clientX,evt.clientY)
console.log(evt.pageX,evt.pageY)
console.log(evt.offsetX,evt.offsetY)
}
// evt.clientX,evt.clientY 距离浏览器可视窗口的左上角的坐标值
// evt.pageX,evt.pageY 距离页面文档流的左上角的坐标值
// evt.offsetX,evt.offsetY 距离出发元素的左上角的坐标值
</script>
</body>
</html>