获取鼠标坐标常用方法
-
offsetX/offsetY
,鼠标点击位置离事件元素边框的距离,事件元素左上角坐标为(0,0)
-
clientX/clientY
,鼠标点击位置相对于浏览器(这里说的是浏览器的有效区域)的距离,不包含滚动距离
-
pageX/pageY
,clientX/Y+横/纵向滚动的距离
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
</head>
<style>
body{
margin: 0px;
}
.getInfo{
width: 200px;
height: 220px;
background-color: #bae9d9;
border: 4px solid pink;
margin: 10px 5px 8px 20px;
padding: 7px 15px;
}
</style>
<body>
<div class="getInfo"> </div>
</body>
<script>
let getInfo = document.getElementsByClassName('getInfo')[0]
getInfo.onmousedown = function(e){
}
</script>
</html>