Convert Figma logo to code with AI

rnosov logoreact-reveal

Easily add reveal on scroll animations to your React app

2,725
180
2,725
94

Top Related Projects

🎊 A collection of animations for inline style libraries

26,486

Animate on scroll library

Effortless animation between DOM changes (eg. list reordering) using the FLIP technique.

Animate elements as they scroll into view.

✌️ A spring physics based React animation library

An easy way to perform animations when a React component enters or leaves the DOM

Quick Overview

React Reveal is a popular animation library for React applications. It provides a set of components that allow developers to easily add reveal animations to their React elements, enhancing the user experience with smooth and customizable entrance animations.

Pros

  • Easy to use with minimal setup required
  • Wide variety of pre-built animation effects
  • Customizable animation properties
  • Supports server-side rendering

Cons

  • Limited to entrance animations only
  • May impact performance if overused
  • Lacks advanced animation sequencing capabilities
  • Not actively maintained (last update was in 2019)

Code Examples

Basic Fade animation:

import Fade from 'react-reveal/Fade';

function MyComponent() {
  return (
    <Fade>
      <h1>This will fade in</h1>
    </Fade>
  );
}

Zoom animation with custom duration:

import Zoom from 'react-reveal/Zoom';

function MyComponent() {
  return (
    <Zoom duration={2000}>
      <p>This will zoom in over 2 seconds</p>
    </Zoom>
  );
}

Bounce animation with delay:

import Bounce from 'react-reveal/Bounce';

function MyComponent() {
  return (
    <Bounce delay={1000}>
      <button>This button will bounce after a 1-second delay</button>
    </Bounce>
  );
}

Getting Started

  1. Install the package:

    npm install react-reveal
    
  2. Import and use the desired animation component in your React code:

    import Fade from 'react-reveal/Fade';
    
    function App() {
      return (
        <div>
          <h1>Welcome to my app</h1>
          <Fade bottom>
            <p>This content will fade in from the bottom</p>
          </Fade>
        </div>
      );
    }
    
    export default App;
    
  3. Customize animations using props like duration, delay, distance, etc.

Competitor Comparisons

🎊 A collection of animations for inline style libraries

Pros of react-animations

  • Offers a wider range of animation options, including more complex animations
  • Provides greater flexibility in customizing animations
  • Can be used with various CSS-in-JS libraries, not limited to a specific implementation

Cons of react-animations

  • Requires more setup and configuration compared to react-reveal
  • Less beginner-friendly, with a steeper learning curve
  • May require additional dependencies for optimal use

Code Comparison

react-animations:

import { fadeIn } from 'react-animations';
import styled, { keyframes } from 'styled-components';

const fadeInAnimation = keyframes`${fadeIn}`;
const FadeInDiv = styled.div`animation: 1s ${fadeInAnimation};`;

react-reveal:

import Fade from 'react-reveal/Fade';

<Fade>
  <h1>React Reveal</h1>
</Fade>

react-animations provides raw animation keyframes that can be used with various styling solutions, while react-reveal offers pre-built components with built-in animations. react-animations requires more setup but offers greater flexibility, whereas react-reveal provides a simpler, more straightforward approach to adding animations to React components.

26,486

Animate on scroll library

Pros of AOS

  • Framework-agnostic, works with any JavaScript project
  • Simpler setup and usage, doesn't require React knowledge
  • Offers more animation options out-of-the-box

Cons of AOS

  • Less performant for complex animations or large numbers of elements
  • Lacks fine-grained control over animation timing and sequencing
  • Not specifically optimized for React applications

Code Comparison

AOS:

<div data-aos="fade-up" data-aos-duration="1000">
  Animate me!
</div>

React Reveal:

import Fade from 'react-reveal/Fade';

<Fade bottom>
  <div>Animate me!</div>
</Fade>

Summary

AOS is a versatile animation library that works across different frameworks, making it easier to implement for developers who aren't React specialists. It offers a wide range of pre-built animations and simple HTML-based configuration. However, React Reveal is more performant and provides better control over animations in React applications. React Reveal's component-based approach integrates more seamlessly with React's ecosystem, while AOS requires additional setup to work optimally in React projects. Choose AOS for simpler, framework-agnostic animations, and React Reveal for more complex, React-specific animation needs.

Effortless animation between DOM changes (eg. list reordering) using the FLIP technique.

Pros of react-flip-move

  • Focuses specifically on list animations, providing smooth transitions for adding, removing, and reordering items
  • Offers more granular control over animation properties, including duration, easing, and delay
  • Supports both imperative and declarative usage, allowing for greater flexibility

Cons of react-flip-move

  • Limited to list animations, lacking support for other types of reveal effects
  • Requires more setup and configuration compared to the simpler API of react-reveal
  • May have a steeper learning curve for developers new to animation concepts

Code Comparison

react-flip-move:

<FlipMove duration={300} easing="ease-out">
  {items.map(item => (
    <div key={item.id}>{item.content}</div>
  ))}
</FlipMove>

react-reveal:

<Fade bottom cascade>
  {items.map(item => (
    <div key={item.id}>{item.content}</div>
  ))}
</Fade>

Summary

react-flip-move excels in list animations with fine-grained control, while react-reveal offers a broader range of reveal effects with a simpler API. The choice between the two depends on the specific animation requirements of your project and the level of control you need over the animations.

Animate elements as they scroll into view.

Pros of ScrollReveal

  • Framework-agnostic, works with vanilla JavaScript and various frameworks
  • More customizable animation options and sequences
  • Smaller bundle size and potentially better performance

Cons of ScrollReveal

  • Requires more manual setup and configuration
  • Less React-specific features and integration
  • May require additional work to achieve component-based animations

Code Comparison

ScrollReveal:

ScrollReveal().reveal('.element', {
  delay: 200,
  distance: '50px',
  origin: 'bottom',
  duration: 1000
});

React Reveal:

import Fade from 'react-reveal/Fade';

<Fade bottom>
  <div>Content to reveal</div>
</Fade>

Summary

ScrollReveal offers more flexibility and can be used across different frameworks, while React Reveal provides a more React-centric approach with easier integration for React projects. ScrollReveal requires more manual configuration but offers finer control over animations. React Reveal simplifies the process with pre-built components but may have limitations in customization. The choice between the two depends on the specific project requirements, desired level of control, and the development framework being used.

✌️ A spring physics based React animation library

Pros of react-spring

  • More flexible and powerful animation system, allowing for complex physics-based animations
  • Better performance due to its use of native browser animations and requestAnimationFrame
  • Larger and more active community, resulting in frequent updates and extensive documentation

Cons of react-spring

  • Steeper learning curve, especially for developers new to animation libraries
  • More verbose syntax for simple animations compared to React Reveal
  • Larger bundle size, which may impact initial load times for smaller projects

Code Comparison

React Reveal:

import Fade from 'react-reveal/Fade';

<Fade>
  <h1>Hello, World!</h1>
</Fade>

react-spring:

import { useSpring, animated } from 'react-spring';

const props = useSpring({ opacity: 1, from: { opacity: 0 } });
return <animated.h1 style={props}>Hello, World!</animated.h1>;

Both libraries offer ways to create animations in React applications, but react-spring provides more granular control over the animation process at the cost of increased complexity. React Reveal focuses on simplicity and ease of use for common animation patterns, while react-spring offers a more comprehensive solution for advanced animation needs.

An easy way to perform animations when a React component enters or leaves the DOM

Pros of React Transition Group

  • More flexible and customizable for complex animations
  • Better integration with React's lifecycle methods
  • Supports both CSS and JavaScript animations

Cons of React Transition Group

  • Steeper learning curve and more complex implementation
  • Requires more boilerplate code for basic animations
  • Less out-of-the-box animation options compared to React Reveal

Code Comparison

React Transition Group:

<CSSTransition
  in={inProp}
  timeout={200}
  classNames="fade"
  unmountOnExit
>
  <div>I'll fade in and out</div>
</CSSTransition>

React Reveal:

<Fade>
  <div>I'll fade in when scrolled into view</div>
</Fade>

React Transition Group provides more granular control over the animation process, allowing developers to define enter and exit states explicitly. React Reveal, on the other hand, offers a simpler API with pre-defined animations that can be easily applied to components.

While React Transition Group is more powerful for complex scenarios, React Reveal excels in quickly adding scroll-based animations with minimal setup. The choice between the two depends on the specific requirements of your project and the level of animation complexity needed.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React Reveal

React Reveal is an animation framework for React. It's MIT licensed, has a tiny footprint and written specifically for React in ES6. It can be used to create various cool reveal on scroll animations in your application. If you liked this package, don't forget to star the Github repository.

Live Examples

A number of simple effect examples:

Also, there are more complicated examples of animated form errors and a todo app.

Search Engine Visibility

react-reveal is regularly checked against googlebot in the Google Search Console to make sure that googlebot can see the content in the revealed elements.

Full Documentation

For a full documentation please visit online docs.

Installation

In the command prompt run:

npm install react-reveal --save

Alternatively you may use yarn:

yarn add react-reveal

Quick Start

Import effects from React Reveal to your project. Lets try Zoom effect first:

import Zoom from 'react-reveal/Zoom';

Place the following code somewhere in your render method:

<Zoom>
  <p>Markup that will be revealed on scroll</p>
</Zoom>

You should see zooming animation that reveals text inside the tag. You can change this text to any JSX you want. If you place this code further down the page you'll see that it'd appear as you scroll down.

Revealing React Components

You may just wrap your custom React component with the effect of your choosing like so:

<Zoom>  
  <CustomComponent />
</Zoom>

In such case, in the resulting <CustomComponent /> HTML markup will be wrapped in a div tag. If you would rather have a different HTML tag then wrap <CustomComponent /> in a tag of your choosing:

<Zoom>
  <section>
    <CustomComponent />   
  </section>
</Zoom>

or if you want to customize div props:

<Zoom>
  <div className="some-class">
    <CustomComponent />   
  </div>
</Zoom>

Revealing Images

If you want to reveal an image you can wrap img tag with with the desired react-reveal effect:

<Zoom>
  <img height="300" width="400" src="https://source.unsplash.com/random/300x400" />
</Zoom>

It would be a very good idea to specify width and height of any image you wish to reveal.

Children

react-reveal will attach a reveal effect to each child it gets. In other words,

<Zoom>
  <div>First Child</div>
  <div>Second Child</div>
</Zoom>

will be equivalent to:

<Zoom>
  <div>First Child</div>
</Zoom>
<Zoom>
  <div>Second Child</div>
</Zoom>  

If you don't want this to happen, you should wrap multiple children in a div tag:

<Zoom>
  <div>
    <div>First Child</div>
    <div>Second Child</div>
  </div>
</Zoom>

Server Side Rendering

react-reveal supports server side rendering out of the box. In some cases, when the javascript bundle arrives much later than the HTML&CSS it might cause a flickering. To prevent this react-reveal will not apply reveal effects on the initial load. Another option is to apply gentle fadeout effect on the initial render. You can force it on all react-reveal elements by placing the following code somewhere near the entry point of your app:

import config from 'react-reveal/globals';

config({ ssrFadeout: true });

Or you you can do it on a per element basis using ssrFadeout prop:

<Zoom ssrFadeout><h1>Content</h1></Zoom>

One last option is to use ssrReveal prop. If enabled, this option will suppress both flickering and ssrFadeout effect. The unfortunate drawback of this option is that the revealed content will appear hidden to Googlebot and to anyone with javascript switched off. So it will makes sense for images and/or headings which are duplicated elsewhere on the page.

Forking This Package

Clone the this repository using the following command:

git clone https://github.com/rnosov/react-reveal.git

In the cloned directory, you can run following commands:

npm install

Installs required node modules

npm run build

Builds the package for production to the dist folder

npm test

Runs tests

License

Copyright © 2018 Roman Nosov. Project source code is licensed under the MIT license.

NPM DownloadsLast 30 Days