Code Monkey home page Code Monkey logo

react-text-loop's Introduction

react-text-loop

text-loop2

An animated loop of text nodes for your headings. Uses react-motion for the transition so it handles super fast animations and spring params.

npm version npm downloads gzip size MIT License PRs Welcome


Installation

npm install react-text-loop or yarn add react-text-loop

How to use

Edit react-text-loop

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

Usage

import TextLoop from "react-text-loop";
import Link from "react-router";
import { BodyText } from "./ui";

class App extends Component {
    render() {
        return (
            <h2>
                <TextLoop>
                    <span>First item</span>
                    <Link to="/">Second item</Link>
                    <BodyText>Third item</BodyText>
                </TextLoop>{" "}
                and something else.
            </h2>
        );
    }
}

Props

Prop Type Default Definition
interval number | array 3000 The frequency (in ms) that the words change. Can also pass an array if you want a different interval per children
delay number 0 A delay (in ms) for the animation to start. This allows to use multiple instances to create a staggered animation effect for example.
adjustingSpeed number 150 The speed that the container around each word adjusts to the next one (in ms). Usually you don't need to change this.
fade boolean true Enable or disable the fade animation on enter and leave
mask boolean false Mask the animation around the bounding box of the animated content
noWrap boolean true Disable whitepace: 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.
springConfig object { stiffness: 340, damping: 30 } Configuration for react-motion spring
className string Any additional CSS classes you might want to use to style the image
children node The words you want to loop (required)

Caveats

Because <TextLoop> loops through its children nodes, only root-level nodes will be considered so doing 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 for each node.

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

Examples

Fast transition

text-loop-fast-small

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

Wobbly animation

text-loop-bouncy

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

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

Contributing

Please follow our contributing guidelines.

License

MIT

react-text-loop's People

Contributors

braposo avatar andrinealver avatar kenime avatar abhijitparida avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.