-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"created cursor component with wang image
with '#' will be ignored, and an empty message aborts the commit.
- Loading branch information
1 parent
f9c6f1e
commit 35bba11
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use client"; | ||
|
||
import React, { useState, useEffect } from "react"; | ||
import Image from 'next/image' | ||
|
||
const Cursor = () => { | ||
const [position, setPosition] = useState({ x: 0, y: 0 }); | ||
|
||
const [isPointer, setIsPointer] = useState(false); | ||
|
||
const handleMouseMove = (e: any) => { | ||
setPosition({ x: e.clientX, y: e.clientY }); | ||
|
||
const target = e.target; | ||
|
||
setIsPointer( | ||
window.getComputedStyle(target).getPropertyValue("cursor") === "pointer" | ||
); | ||
|
||
e.stopPropagation(); | ||
}; | ||
|
||
useEffect(() => { | ||
window.addEventListener("mousemove", handleMouseMove); | ||
|
||
return () => window.removeEventListener("mousemove", handleMouseMove); | ||
}, []); | ||
|
||
const YSize = isPointer ? 0 : 100; | ||
const XSize = isPointer ? 0 : 20; | ||
const rotationAngle = isPointer ? 0 : 315; | ||
var topPos = position.y - YSize / 2; | ||
|
||
const cursorStyle = isPointer ? { display: "none" } : { transform: `rotate(${rotationAngle}deg)`, cursor: "none"}; | ||
|
||
return ( | ||
<Image | ||
src={"/landing/wand.png"} | ||
alt="Custom Cursor" | ||
width = {XSize} | ||
height = {YSize} | ||
style={{ | ||
...cursorStyle, | ||
position: "fixed", | ||
left: `${position.x - XSize / 2}px`, | ||
top:`${topPos}px`, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default Cursor; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.