react-components/cursor.jsx

38 lines
949 B
React
Raw Normal View History

2024-10-26 21:36:28 +02:00
"use client";
import { useEffect, useRef } from 'react';
import { gsap } from 'gsap';
const CustomCursor = ({ isHoveringButton }) => {
const cursorRef = useRef(null);
useEffect(() => {
const moveCursor = (e) => {
const { clientX: x, clientY: y } = e;
gsap.to(cursorRef.current, {
x: x - 16,
y: y - 16,
duration: 0.1,
ease: "power3.out",
});
};
window.addEventListener('mousemove', moveCursor);
return () => {
window.removeEventListener('mousemove', moveCursor);
};
}, []);
return (
<>
<div
ref={cursorRef}
className={`pointer-events-none fixed top-0 left-0 ${isHoveringButton ? 'invisible' : ''} w-10 h-10 bg-white rounded-full z-50 mix-blend-difference`}
/>
</>
);
};
export default CustomCursor;