-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.ts
34 lines (27 loc) · 942 Bytes
/
script.ts
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
const images: string[] = []
for (let index = 0; index < 16; index++) {
images.push(`assets/${index}.png`)
}
let currentImageIndex = 0;
let lastX = 0;
let lastY = 0;
document.addEventListener('mousemove', (event) => {
const { clientX: x, clientY: y } = event;
if (Math.abs(x - lastX) > 50 || Math.abs(y - lastY) > 50) {
lastX = x;
lastY = y;
const cursorImage = document.createElement('img');
cursorImage.src = images[currentImageIndex];
cursorImage.classList.add('cursor-image');
cursorImage.style.left = `${x}px`;
cursorImage.style.top = `${y}px`;
document.body.appendChild(cursorImage);
setTimeout(() => {
cursorImage.classList.add('fade-out');
setTimeout(() => {
cursorImage.remove();
}, 500);
}, 1000);
currentImageIndex = (currentImageIndex + 1) % images.length;
}
});