<!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>
div{
position: absolute;
font-family: 'Times New Roman';
font-size: 25px;
font-weight: bolder;
width: 100px;
height: 50px;
line-height: 30px;
color: blueviolet;
cursor: pointer;
}
</style>
</head>
<body>
<div></div>
<script>
window.addEventListener('mousemove',function(e){
let x = e.clientX;
let y = e.clientY;
let mydiv = document.querySelector('div');
mydiv.innerHTML = `(${x}px,${y}px)`;
mydiv.style.left = x + 'px';
mydiv.style.top = y + 'px';
})
</script>
</body>
</html>
JS实现当鼠标在浏览器窗口中移动时,在鼠标指针旁边显示指针的坐标
最新推荐文章于 2024-06-05 00:30:00 发布