Skip to content

Commit 35bba11

Browse files
committed
"created cursor component with wang image
with '#' will be ignored, and an empty message aborts the commit.
1 parent f9c6f1e commit 35bba11

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

app/ui/cursor.tsx

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"use client";
2+
3+
import React, { useState, useEffect } from "react";
4+
import Image from 'next/image'
5+
6+
const Cursor = () => {
7+
const [position, setPosition] = useState({ x: 0, y: 0 });
8+
9+
const [isPointer, setIsPointer] = useState(false);
10+
11+
const handleMouseMove = (e: any) => {
12+
setPosition({ x: e.clientX, y: e.clientY });
13+
14+
const target = e.target;
15+
16+
setIsPointer(
17+
window.getComputedStyle(target).getPropertyValue("cursor") === "pointer"
18+
);
19+
20+
e.stopPropagation();
21+
};
22+
23+
useEffect(() => {
24+
window.addEventListener("mousemove", handleMouseMove);
25+
26+
return () => window.removeEventListener("mousemove", handleMouseMove);
27+
}, []);
28+
29+
const YSize = isPointer ? 0 : 100;
30+
const XSize = isPointer ? 0 : 20;
31+
const rotationAngle = isPointer ? 0 : 315;
32+
var topPos = position.y - YSize / 2;
33+
34+
const cursorStyle = isPointer ? { display: "none" } : { transform: `rotate(${rotationAngle}deg)`, cursor: "none"};
35+
36+
return (
37+
<Image
38+
src={"/landing/wand.png"}
39+
alt="Custom Cursor"
40+
width = {XSize}
41+
height = {YSize}
42+
style={{
43+
...cursorStyle,
44+
position: "fixed",
45+
left: `${position.x - XSize / 2}px`,
46+
top:`${topPos}px`,
47+
}}
48+
/>
49+
);
50+
};
51+
52+
export default Cursor;

public/landing/wand.png

45 KB
Loading

0 commit comments

Comments
 (0)