-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdots_track_mouse_coordinates.html
More file actions
66 lines (58 loc) · 1.41 KB
/
dots_track_mouse_coordinates.html
File metadata and controls
66 lines (58 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mouse Tracker with Dot</title>
<style>
body {
margin: 0;
background-color: white;
height: 100vh;
font-family: Arial, sans-serif;
font-size: 24px;
overflow: hidden;
}
#coords {
position: absolute;
top: 20px;
left: 20px;
color: black;
background: rgba(255, 255, 255, 0.8);
padding: 10px;
z-index: 1000;
}
.tracker-dot {
position: absolute;
width: 10px;
height: 10px;
background-color: red;
border-radius: 50%;
pointer-events: none;
}
#dot-horizontal {
top: 50px;
transform: translateY(-50%);
}
#dot-vertical {
left: 50px;
transform: translateX(-50%);
}
</style>
</head>
<body>
<div id="coords">X: 0, Y: 0</div>
<div id="dot-horizontal" class="tracker-dot"></div>
<div id="dot-vertical" class="tracker-dot"></div>
<script>
const coordsDisplay = document.getElementById('coords');
const dotH = document.getElementById('dot-horizontal');
const dotV = document.getElementById('dot-vertical');
document.addEventListener('mousemove', (e) => {
const { clientX, clientY } = e;
coordsDisplay.textContent = `X: ${clientX}, Y: ${clientY}`;
dotH.style.left = `${clientX}px`;
dotV.style.top = `${clientY}px`;
});
</script>
</body>
</html>