morphing-cursor
jolyui-ui/morphing-cursorFreeComponent
jolyui/ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by jolyui/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://jolyui.dev/r/morphing-cursor.jsonSource
1"use client";23import type React from "react";4import { useCallback, useEffect, useRef, useState } from "react";5import { cn } from "@/lib/utils";67interface MagneticTextProps {8 text: string;9 hoverText?: string;10 className?: string;11}1213export function MagneticText({14 text = "CREATIVE",15 hoverText = "EXPLORE",16 className,17}: MagneticTextProps) {18 const containerRef = useRef<HTMLDivElement>(null);19 const circleRef = useRef<HTMLDivElement>(null);20 const innerTextRef = useRef<HTMLDivElement>(null);21 const [isHovered, setIsHovered] = useState(false);22 const [containerSize, setContainerSize] = useState({ width: 0, height: 0 });2324 const mousePos = useRef({ x: 0, y: 0 });25 const currentPos = useRef({ x: 0, y: 0 });26 const animationFrameRef = useRef<number | undefined>(undefined);2728 useEffect(() => {29 const updateSize = () => {30 if (containerRef.current) {31 setContainerSize({32 width: containerRef.current.offsetWidth,33 height: containerRef.current.offsetHeight,34 });35 }36 };37 updateSize();38 window.addEventListener("resize", updateSize);39 return () => window.removeEventListener("resize", updateSize);40 }, []);4142 useEffect(() => {43 const lerp = (start: number, end: number, factor: number) =>44 start + (end - start) * factor;4546 const animate = () => {47 currentPos.current.x = lerp(48 currentPos.current.x,49 mousePos.current.x,50 0.15,51 );52 currentPos.current.y = lerp(53 currentPos.current.y,54 mousePos.current.y,55 0.15,56 );5758 if (circleRef.current) {59 circleRef.current.style.transform = `translate(${currentPos.current.x}px, ${currentPos.current.y}px) translate(-50%, -50%)`;60 }6162 if (innerTextRef.current) {63 innerTextRef.current.style.transform = `translate(${-currentPos.current.x}px, ${-currentPos.current.y}px)`;64 }6566 animationFrameRef.current = requestAnimationFrame(animate);67 };6869 animationFrameRef.current = requestAnimationFrame(animate);70 return () => {71 if (animationFrameRef.current)72 cancelAnimationFrame(animationFrameRef.current);73 };74 }, []);7576 const handleMouseMove = useCallback((e: React.MouseEvent<HTMLDivElement>) => {77 if (!containerRef.current) return;78 const rect = containerRef.current.getBoundingClientRect();79 mousePos.current = {80 x: e.clientX - rect.left,81 y: e.clientY - rect.top,82 };83 }, []);8485// … truncated
Files it writes
More from jolyui/ui
All 199 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-prompt-boxai-prompt-box | jolyui/ui | Components | Free | 4 deps | |
| animated-beamanimated-beam | jolyui/ui | Components | Free | 1 dep | |
| animated-tableanimated-table | jolyui/ui | Components | Free | 2 deps | |
| animated-theme-toggleanimated-theme-toggle | jolyui/ui | Components | Free | 2 deps | |
| animated-toastanimated-toast | jolyui/ui | Components | Free | 2 deps | |
| animated-tooltipanimated-tooltip | jolyui/ui | Components | Free | 1 dep | |
| bento-gridbento-grid | jolyui/ui | Components | Free | no deps | |
| buttonbutton | jolyui/ui | Components | Free | 3 deps |
