Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Animate words in your headings

License

NotificationsYou must be signed in to change notification settings

braposo/react-text-loop

Repository files navigation

text-loop2

An animated loop of text nodes for your headings. Usesreact-motion for the transition so it handles super fastanimations and spring params.

npm versionnpm downloadsgzip sizeMIT LicensePRs Welcome


Installation

npm install react-text-loop oryarn add react-text-loop

How to use

Edit react-text-loop

You can also run the examples by cloning the repo and runningyarn start.

Usage

importTextLoopfrom"react-text-loop";importLinkfrom"react-router";import{BodyText}from"./ui";classAppextendsComponent{render(){return(<h2><TextLoop><span>First item</span><Linkto="/">Second item</Link><BodyText>Third item</BodyText></TextLoop>{" "}                and something else.</h2>);}}

Props

PropTypeDefaultDefinition
intervalnumber | array3000The frequency (in ms) that the words change. Can also pass an array if you want a different interval per children
delaynumber0A delay (in ms) for the animation to start. This allows to use multiple instances to create a staggered animation effect for example.
adjustingSpeednumber150The speed that the container around each word adjusts to the next one (in ms). Usually you don't need to change this.
fadebooleantrueEnable or disable the fade animation on enter and leave
maskbooleanfalseMask the animation around the bounding box of the animated content
noWrapbooleantrueDisablewhitepace: nowrap style for each element. This is used by default so we can always get the right width of the element but can have issues sometimes.
springConfigobject{ stiffness: 340, damping: 30 }Configuration forreact-motion spring
classNamestringAny additional CSS classes you might want to use to style the image
childrennodeThe words you want to loop (required)

Caveats

Because<TextLoop> loops through its children nodes, only root-level nodes will be considered sodoing something like:

<TextLoop><div><span>First item</span><span>Second item</span></div><div>Third item</div></TextLoop>;

will make first and second item to be treated as one and animate together.

You can also just send a normal array as children prop if you don't need any individual styling foreach node.

<TextLoopchildren={["Trade faster","Increase sales","Stock winners","Price perfectly"]}/>;

Examples

Fast transition

text-loop-fast-small

<TextLoopinterval={100}>...</TextLoop>;

Wobbly animation

text-loop-bouncy

<TextLoopspringConfig={{stiffness:180,damping:8}}>...</TextLoop>;

For many other examples, please have a look at theCodeSandbox playground.

Contributing

Please follow ourcontributing guidelines.

License

MIT

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp