Skip to content

Commit 33c8cf7

Browse files
committed
Mouse dots
1 parent a8eea6c commit 33c8cf7

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# JavaScript-Sandpit
2+
23
Messing about with JavaScript
34

45
* https://johnstack.github.io/JavaScript-Sandpit/background_colour_mouse_movement.html
56
* https://johnstack.github.io/JavaScript-Sandpit/background_colour_time_of_day.html
67
* https://johnstack.github.io/JavaScript-Sandpit/big_cube_mouse_movement.html
78
* https://johnstack.github.io/JavaScript-Sandpit/small_cube_mouse_movement.html
89
* https://johnstack.github.io/JavaScript-Sandpit/trippy_cursor_colours.html
10+
* https://johnstack.github.io/JavaScript-Sandpit/dots_track_mouse_coordinates

dots_track_mouse_coordinates.html

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

0 commit comments

Comments
 (0)