Proximity Text
pixelflow-ui/proximity-textFreeComponent
pixelflow-ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by pixelflow-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://pixelflowui.lok1.dev/r/proximity-text.jsonSource
1"use client";23import React, { useEffect, useRef } from "react";45const ProximityText = ({ text }) => {6 const wordRef = useRef([]);7 const isHoverRef = useRef(false);8 const rectsRef = useRef([]);910 const cacheRects = () => {11 rectsRef.current = wordRef.current.map((el) => el.getBoundingClientRect());12 };1314 const resetWeights = () => {15 wordRef.current.forEach((el) => (el.style.fontWeight = "400"));16 };1718 useEffect(() => {19 const handleMouse = (e) => {20 if (!isHoverRef.current) return;21 const mouseX = e.clientX;22 const maxDistance = 30;2324 rectsRef.current.forEach((rect, i) => {25 const centerX = rect.left + rect.width / 2;26 const distance = Math.abs(mouseX - centerX);27 const weight = Math.max(28 400,29 Math.round(900 - (distance / maxDistance) * 500)30 );31 wordRef.current[i].style.fontWeight = String(weight);32 });33 };3435 window.addEventListener("mousemove", handleMouse);36 return () => window.removeEventListener("mousemove", handleMouse);37 }, []);3839 return (40 <span41 onMouseEnter={() => {42 isHoverRef.current = true;43 cacheRects();44 }}45 onMouseLeave={() => {46 isHoverRef.current = false;47 resetWeights();48 }}49 className="cursor-pointer inline-flex"50 >51 {text.split("").map((letter, i) => (52 <span53 ref={(el) => {54 if (el) wordRef.current[i] = el;55 }}56 key={i}57 className="transition-all duration-150 font-[family-name:var(--font-inter)]"58 >59 {letter === " " ? "\u00A0" : letter}60 </span>61 ))}62 </span>63 );64};6566export default function Demo() {67 return (68 <div className="flex items-center justify-center text-4xl text-white">69 <ProximityText text="Hover over me" />70 </div>71 );72}73
Files it writes
More from pixelflow-ui
All 35 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordion Lyraaccordion-lyra | pixelflow-ui | Components | Free | 3 deps | |
| Accordion Novaaccordion-nova | pixelflow-ui | Components | Free | 3 deps | |
| Accordion Retroaccordion-retro | pixelflow-ui | Components | Free | 3 deps | |
| Background 1background-1 | pixelflow-ui | Components | Free | no deps | |
| Background 1Retrobackground-1-retro | pixelflow-ui | Components | Free | no deps | |
| Bouncy Input Lyrabouncy-input-lyra | pixelflow-ui | Components | Free | 1 dep | |
| Bouncy Input Novabouncy-input-nova | pixelflow-ui | Components | Free | 1 dep | |
| Bouncy Input Retrobouncy-input-retro | pixelflow-ui | Components | Free | 1 dep |
