Commit 35bba11 1 parent f9c6f1e commit 35bba11 Copy full SHA for 35bba11
File tree 2 files changed +52
-0
lines changed
2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments