react-reveal

Easily add reveal on scroll animations to your React app

README

React Reveal


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

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:

  1. ```sh
  2. npm install react-reveal --save
  3. ```

Alternatively you may use yarn:

  1. ```sh
  2. yarn add react-reveal
  3. ```

Quick Start


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

  1. ``` js
  2. import Zoom from 'react-reveal/Zoom';
  3. ```

Place the following code somewhere in your render method:

  1. ``` js
  2. <Zoom>
  3.   <p>Markup that will be revealed on scroll</p>
  4. </Zoom>
  5. ```

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:

  1. ``` js
  2. <Zoom>  
  3.   <CustomComponent />
  4. </Zoom>
  5. ```

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

  1. ``` js
  2. <Zoom>
  3.   <section>
  4.     <CustomComponent />  
  5.   </section>
  6. </Zoom>
  7. ```

or if you want to customize div props:

  1. ``` js
  2. <Zoom>
  3.   <div className="some-class">
  4.     <CustomComponent />  
  5.   </div>
  6. </Zoom>
  7. ```

Revealing Images


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

  1. ``` js
  2. <Zoom>
  3.   <img height="300" width="400" src="https://source.unsplash.com/random/300x400" />
  4. </Zoom>
  5. ```

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,

  1. ``` js
  2. <Zoom>
  3.   <div>First Child</div>
  4.   <div>Second Child</div>
  5. </Zoom>
  6. ```

will be equivalent to:

  1. ``` js
  2. <Zoom>
  3.   <div>First Child</div>
  4. </Zoom>
  5. <Zoom>
  6.   <div>Second Child</div>
  7. </Zoom>  
  8. ```

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

  1. ``` js
  2. <Zoom>
  3.   <div>
  4.     <div>First Child</div>
  5.     <div>Second Child</div>
  6.   </div>
  7. </Zoom>
  8. ```

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:

  1. ``` js
  2. import config from 'react-reveal/globals';

  3. config({ ssrFadeout: true });
  4. ```

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

  1. ``` js
  2. <Zoom ssrFadeout><h1>Content</h1>Zoom>
  3. ```

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:

  1. ```sh
  2. git clone https://github.com/rnosov/react-reveal.git
  3. ```

In the cloned directory, you can run following commands:

  1. ```sh
  2. npm install
  3. ```

Installs required node modules

  1. ```sh
  2. npm run build
  3. ```

Builds the package for production to the dist folder

  1. ```sh
  2. npm test
  3. ```

Runs tests

License


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