Scramble Hover
fancy/scramble-hoverFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/scramble-hover.jsonSource
1"use client"23import { useEffect, useState } from "react"4import { motion } from "motion/react"56import { cn } from "@/lib/utils"78interface ScrambleHoverProps {9 text: string10 scrambleSpeed?: number11 maxIterations?: number12 sequential?: boolean13 revealDirection?: "start" | "end" | "center"14 useOriginalCharsOnly?: boolean15 characters?: string16 className?: string17 scrambledClassName?: string18}1920const ScrambleHover: React.FC<ScrambleHoverProps> = ({21 text,22 scrambleSpeed = 50,23 maxIterations = 10,24 useOriginalCharsOnly = false,25 characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+",26 className,27 scrambledClassName,28 sequential = false,29 revealDirection = "start",30 ...props31}) => {32 const [displayText, setDisplayText] = useState(text)33 const [isHovering, setIsHovering] = useState(false)34 const [isScrambling, setIsScrambling] = useState(false)35 const [revealedIndices, setRevealedIndices] = useState(new Set<number>())3637 useEffect(() => {38 let interval: NodeJS.Timeout39 let currentIteration = 04041 const getNextIndex = () => {42 const textLength = text.length43 switch (revealDirection) {44 case "start":45 return revealedIndices.size46 case "end":47 return textLength - 1 - revealedIndices.size48 case "center":49 const middle = Math.floor(textLength / 2)50 const offset = Math.floor(revealedIndices.size / 2)51 const nextIndex =52 revealedIndices.size % 2 === 053 ? middle + offset54 : middle - offset - 15556 if (57 nextIndex >= 0 &&58 nextIndex < textLength &&59 !revealedIndices.has(nextIndex)60 ) {61 return nextIndex62 }6364 for (let i = 0; i < textLength; i++) {65 if (!revealedIndices.has(i)) return i66 }67 return 068 default:69 return revealedIndices.size70 }71 }7273 const shuffleText = (text: string) => {74 if (useOriginalCharsOnly) {75 const positions = text.split("").map((char, i) => ({76 char,77 isSpace: char === " ",78 index: i,79 isRevealed: revealedIndices.has(i),80 }))8182 const nonSpaceChars = positions83 .filter((p) => !p.isSpace && !p.isRevealed)84 .map((p) => p.char)8586 // Shuffle remaining non-revealed, non-space characters87 for (let i = nonSpaceChars.length - 1; i > 0; i--) {88// … truncated
What it pulls in
npm packages
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient With Svganimated-gradient-with-svg | fancy | Components | Free | no deps | |
| Basic Number Tickerbasic-number-ticker | fancy | Components | Free | 1 dep | |
| Box Carouselbox-carousel | fancy | Components | Free | 1 dep | |
| Breathing Textbreathing-text | fancy | Components | Free | 1 dep | |
| Circling Elementscircling-elements | fancy | Components | Free | 1 dep | |
| Css Boxcss-box | fancy | Components | Free | 1 dep | |
| Cursor Attractor And Gravitycursor-attractor-and-gravity | fancy | Components | Free | 5 deps | |
| Drag Elementsdrag-elements | fancy | Components | Free | 1 dep |
