Download src/components/ui/interactive-cursor.tsx from felix-fx/fx-1: direct link, hf CLI and curl.
- Browser
- Download file 2.4 kB
-
https://huggingface.co/felix-fx/fx-1/resolve/main/src/components/ui/interactive-cursor.tsx
- Command line
-
hf download hf://felix-fx/fx-1/src/components/ui/interactive-cursor.tsx
-
curl -L -o interactive-cursor.tsx https://huggingface.co/felix-fx/fx-1/resolve/main/src/components/ui/interactive-cursor.tsx
2.4 kB
| import { useEffect, useRef } from 'react'; | |
| export const InteractiveCursor = () => { | |
| const cursorRef = useRef<HTMLDivElement>(null); | |
| const trailRef = useRef<HTMLDivElement>(null); | |
| useEffect(() => { | |
| const cursor = cursorRef.current; | |
| const trail = trailRef.current; | |
| if (!cursor || !trail) return; | |
| let mouseX = 0; | |
| let mouseY = 0; | |
| let trailX = 0; | |
| let trailY = 0; | |
| const updateCursor = (e: MouseEvent) => { | |
| mouseX = e.clientX; | |
| mouseY = e.clientY; | |
| cursor.style.left = `${mouseX}px`; | |
| cursor.style.top = `${mouseY}px`; | |
| }; | |
| const animateTrail = () => { | |
| trailX += (mouseX - trailX) * 0.1; | |
| trailY += (mouseY - trailY) * 0.1; | |
| trail.style.left = `${trailX}px`; | |
| trail.style.top = `${trailY}px`; | |
| requestAnimationFrame(animateTrail); | |
| }; | |
| const handleMouseEnterButton = () => { | |
| cursor.style.transform = 'translate(-50%, -50%) scale(1.5)'; | |
| cursor.style.mixBlendMode = 'difference'; | |
| }; | |
| const handleMouseLeaveButton = () => { | |
| cursor.style.transform = 'translate(-50%, -50%) scale(1)'; | |
| cursor.style.mixBlendMode = 'normal'; | |
| }; | |
| document.addEventListener('mousemove', updateCursor); | |
| // Add hover effects to interactive elements | |
| const interactiveElements = document.querySelectorAll('button, a, [role="button"]'); | |
| interactiveElements.forEach(el => { | |
| el.addEventListener('mouseenter', handleMouseEnterButton); | |
| el.addEventListener('mouseleave', handleMouseLeaveButton); | |
| }); | |
| animateTrail(); | |
| return () => { | |
| document.removeEventListener('mousemove', updateCursor); | |
| interactiveElements.forEach(el => { | |
| el.removeEventListener('mouseenter', handleMouseEnterButton); | |
| el.removeEventListener('mouseleave', handleMouseLeaveButton); | |
| }); | |
| }; | |
| }, []); | |
| return ( | |
| <> | |
| <div | |
| ref={cursorRef} | |
| className="hidden md:block fixed pointer-events-none z-50 w-4 h-4 bg-primary rounded-full transition-transform duration-200 ease-out" | |
| style={{ transform: 'translate(-50%, -50%)' }} | |
| /> | |
| <div | |
| ref={trailRef} | |
| className="hidden md:block fixed pointer-events-none z-40 w-8 h-8 border-2 border-primary/30 rounded-full transition-transform duration-300 ease-out" | |
| style={{ transform: 'translate(-50%, -50%)' }} | |
| /> | |
| </> | |
| ); | |
| }; |