<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
div{
width: 300px;
height: 300px;
background-color: pink;
margin: 100px auto;
}
</style>
</head>
<body>
<div></div>
<script>
var box=document.querySelector('div');
box.addEventListener('mousemove',function (e) {
var x=e.pageX;
var y=e.pageY;
x-=box.offsetLeft;
y-=box.offsetTop;
this.innerHTML=x+', '+y;
})
</script>
</body>
</html>
js 获取鼠标在盒子内部的坐标
最新推荐文章于 2023-07-04 23:05:56 发布