-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplanecursor.jsx
More file actions
55 lines (47 loc) · 1.23 KB
/
planecursor.jsx
File metadata and controls
55 lines (47 loc) · 1.23 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
// src/components/PlaneCursor.jsx
import React, { useEffect, useRef } from "react";
import planeImg from "../assets/plane-icon.webp";
const PlaneCursor = () => {
const planeRef = useRef(null);
useEffect(() => {
let mouseX = 0, mouseY = 0;
let rafId;
const handleMouseMove = (e) => {
mouseX = e.clientX;
mouseY = e.clientY;
if (!rafId) {
rafId = requestAnimationFrame(updatePosition);
}
};
const updatePosition = () => {
if (planeRef.current) {
planeRef.current.style.transform = `translate(${mouseX}px, ${mouseY}px)`;
}
rafId = null;
};
document.addEventListener("mousemove", handleMouseMove);
return () => {
document.removeEventListener("mousemove", handleMouseMove);
cancelAnimationFrame(rafId);
};
}, []);
return (
<div
ref={planeRef}
style={{
position: "fixed",
top: 0,
left: 0,
width: "23px",
height: "23px",
pointerEvents: "none",
backgroundImage: `url(${planeImg})`,
backgroundSize: "contain",
backgroundRepeat: "no-repeat",
zIndex: 9999,
transform: "translate(-50%, -50%)",
}}
/>
);
};
export default PlaneCursor;