Docs
Text
Scroll and Swap Text

Scroll and Swap Text

A text component that swaps the letters vertically on scroll.

SCROLL SLOWLY

Alexandra RodriguezBenjamin ChenCatherine WilliamsDavid MartinezElena PetrovFrancesco RossiGabriela SantosHenrik LarssonIsabella ThompsonJames AndersonKatarina NovakLeonardo SilvaMaria GonzalezNikolai VolkovOlivia JohnsonPablo HernandezQiana WashingtonRicardo LopezSophia KimThomas MuellerUrsula SchmidtViktor PetersenWen LiXavier DuboisYasmin HassanZachary BrownAmelia DavisBruno CostaClara JohanssonDiego MoralesEvelyn TaylorFelix WagnerGrace WilsonHugo AndersenIris NakamuraJulian BeckKira PopovicLucas GarciaMaya PatelNathan ClarkOphelia MartinPietro RomanoQuinn O'BrienRosa FernandezSebastian LeeTara MitchellUlrich WeberValentina RossoWilliam JonesXiomara ReyesYuki TanakaZara AhmedAndre LeclercBeatrice HallCarlos MendozaDelphine MoreauEmilio BianchiFiona MurphyGiovanni ContiHelena SvenssonIvan DimitrovJasmine GreenKai NielsenLuna TorresMarco EspositoNadia KozlovOscar LindbergPenelope WhiteQuincy AdamsRafael VargasStella JacksonTheo Van Der BergUma SharmaVincenzo FerrariWillow ParkerXimena CastilloYolanda KingZander CooperAria BlackwoodBastien DuboisCamille LaurentDante RicciEstelle MoreauFabio SantosGemma WrightHector VegaIngrid HansenJavier RuizKaia StormLiam O'ConnorMila PetrovNoah FischerOctavia BellPhoenix RiveraQuentin GrayRuby AndersonSage ThompsonTobias KleinUnity CrossVera KozlovaWade TurnerXara MoonYork SterlingZoe MartinezAtlas KaneBrielle FoxCaspian ReedDara SinghEden BlakeFalcon KnightGaia StoneHarbor WellsIndigo ValeJuno PierceKnox Rivers

Installation


1pnpm dlx shadcn@latest add "https://fancycomponents.dev/r/scroll-and-swap-text.json"

Understanding the component


The trick here is similar to the Letter Swap Hover component—duplicate the text, then wrapping the them in a container with relative position, then stack the elements vertically. We use useScroll hook from motion to track the scroll position of the container, and use the scrollYProgress value to offset the vertical position of the elements (by setting the y property of the element).

Notes


  • In order to achieve a nice effect, you likely have to play with the container (where to track the scroll) and its offset. Please refer to motion's documentation for more details.

  • Make sure that the container has a non-static position, like relative, fixed, or absolute to ensure scroll offset is calculated correctly.

Props


PropTypeDefaultDescription
children*React.ReactNode-The content to be displayed and animated
asElementType"span"HTML Tag to render the component as
containerRef*React.RefObject<HTMLElement>-Reference to the container element for scroll tracking
offset[string, string]["0 0", "0 1"]Offset configuration for when the animation should start and end relative to the scroll container
classNamestring-Additional CSS classes for styling the component
springConfig{ stiffness?: number, damping?: number, mass?: number }{ stiffness: 200, damping: 30 }Spring animation configuration for smoothing the scroll-based animation