React components to add reveal animations using the Intersection Observer API and CSS Animations.
Installations
npm install react-awesome-reveal
Developer Guide
Typescript
Yes
Module System
ESM
Node Version
20.18.1
NPM Version
10.8.2
Releases
react-awesome-reveal@4.3.1
Published on 21 Dec 2024
react-awesome-reveal@4.3.0
Published on 21 Dec 2024
react-awesome-reveal@4.2.14
Published on 01 Aug 2024
react-awesome-reveal@4.2.13
Published on 23 Jul 2024
react-awesome-reveal@4.2.12
Published on 16 Jun 2024
react-awesome-reveal@4.2.11
Published on 19 May 2024
Contributors
Unable to fetch Contributors
Languages
TypeScript (98.79%)
HTML (0.72%)
JavaScript (0.49%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
3,379,863
Last Day
4,889
Last Week
22,850
Last Month
106,946
Last Year
1,291,655
GitHub Statistics
1,160 Stars
477 Commits
43 Forks
5 Watching
2 Branches
6 Contributors
Bundle Size
31.53 kB
Minified
5.83 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
4.3.1
Package Id
react-awesome-reveal@4.3.1
Unpacked Size
112.43 kB
Size
19.22 kB
File Count
120
NPM Version
10.8.2
Node Version
20.18.1
Publised On
21 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
3,379,863
Last day
-21%
4,889
Compared to previous day
Last week
-21.7%
22,850
Compared to previous week
Last month
3.9%
106,946
Compared to previous month
Last year
50.7%
1,291,655
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
React Awesome Reveal
[!TIP] If you like this library, please consider supporting its creator.
React Awesome Reveal is a library for React apps written in TypeScript that adds reveal animations using the Intersection Observer API to detect when the elements appear in the viewport. Animations are internally provided by Emotion and implemented as CSS Animations to benefit from hardware acceleration.
Table Of Contents
- Features
- Installation
- Quick Start
- Supported Effects
- Custom Animations
- Intersection Observer
- Past Releases
- License
Features
- 🎁 Modern stack – It is built for modern React and supports React 18
- 🏷 TypeScript support – It is written in TypeScript to improve the DX
- 🍃 Lightweight – Very little footprint on your project
- ⚙️ Uses native APIs – Intersection Observer and CSS Animations are now supported by all browsers
- 🚀 Fast – Buttery smooth experience thanks to the use of native asynchronous APIs and hardware acceleration
- 💅 Fully customizable – Define custom animations and let the library render them
- 💻 SSR support – Server Side Rendering works out-of-the-box
- 🌳 Tree-shakeable – Only the parts you use will be included in your final bundle
Installation
To add this package as a dependency to your app, simply run
1npm install react-awesome-reveal @emotion/react --save
or, if you are using Yarn:
1yarn add react-awesome-reveal @emotion/react
or, if you are using PNPM (as I strongly suggest):
1pnpm add react-awesome-reveal @emotion/react
Quick Start
Import effects from React Awesome Reveal to your React component, for example the Fade
effect:
1import { Fade } from "react-awesome-reveal";
Then simply wrap the components you want to animate:
1<Fade> 2 <p>I will gently appear as I enter the viewport</p> 3</Fade>
Supported Effects
The effects currently supported are Bounce
, Fade
, Flip
, Hinge
, JackInTheBox
, Roll
, Rotate
, Slide
and Zoom
. Refer to the Animate.css documentation for the details.
Attention Seekers
Since version 3, attention seeker animations are wrapped by the AttentionSeeker
component, which accepts a prop called effect
that specifies the animation to render (defaults to "bounce”
). The supported effects are: ”bounce"
, "flash"
, "headShake”
, "heartBeat"
, "jello”
, "pulse"
, "rubberBand"
, “shake”
, “shakeX"
, "shakeY”
, "swing”
, "tada"
and “wobble”
.
Again, refer to the Animate.css documentation for the details.
Props
You can pass the following props to the animation components to customize the behavior:
Prop | Description | Values | Default |
---|---|---|---|
cascade | If set, each child of a reveal animation automatically get assigned a delay that takes into account their predecessor (child i enters the viewport after i * delay * damping milliseconds) – useful for animating list items. | true or false | false |
damping | Factor that affects the delay that each animated component in a cascade animation will be assigned. If damping = 1 then the delay will be equal to the animation duration; if damping < 1 then the delay will be lower than the animation duration; if damping > 1 then the delay will be greater than the animation duration. | number | 0.5 (meaning that the delay will be half of the animation duration) |
direction | Origin of the animation (where applicable). | Usually "down" , "left" , "right" or "up" , with some exceptions documented in the code | undefined |
delay | Time to wait before the animation starts (in milliseconds). | number | 0 |
duration | The animation duration (milliseconds). | number | 1000 |
fraction | How much an element should be in viewport before the animation is triggered. | number between 0 and 1 | 0 |
triggerOnce | Specifies if the animation should run only once or everytime an element enters/exits/re-enters the viewport. | true or false | false |
className | The class names to add to the container element. | string | undefined |
style | The inline styles to add to the container element. | React.CSSProperties | undefined |
childClassName | The class names to add to the child element. | string | undefined |
childStyle | The inline styles to add to the child element. | React.CSSProperties | undefined |
onVisibilityChange | Callback executed when the element enters or leaves the viewport. If more than one element is being animated, this function is called on each element. | (inView: boolean, entry: IntersectionObserverEntry) => void | undefined |
Example
To trigger the animation only the first time an element enters the viewport:
1<Slide triggerOnce> 2 <p>I will animate only the first time you see me</p> 3</Slide>
Chaining Multiple Animations
To chain together multiple animations, set the cascade
prop to true
:
1<Fade cascade> 2 <p>I enter first...</p> 3 <p>...then comes my turn...</p> 4 <p>...and finally you see me!</p> 5</Fade>
Play with the damping
prop to alter the delay by which each child will progressively appear:
1<Fade cascade damping={0.1}> 2 <p>I enter first...</p> 3 <p>...then comes my turn...</p> 4 <p>...and finally you see me!</p> 5</Fade>
Custom Animations
Starting from version 3.2.0, you can define custom animations! Simply import the Reveal
component (which is the default export of the library – give it the name you want) and pass it a keyframes
prop:
1import React from "react"; 2import Reveal from "react-awesome-reveal"; 3import { keyframes } from "@emotion/react"; 4 5const customAnimation = keyframes` 6 from { 7 opacity: 0; 8 transform: translate3d(-200px, -100px, 0); 9 } 10 11 to { 12 opacity: 1; 13 transform: translate3d(0, 0, 0); 14 } 15`; 16 17function CustomAnimation({ children }) { 18 return <Reveal keyframes={customAnimation}>{children}</Reveal>; 19}
If no keyframes
prop is passed, the default rendered animation is a fading entrance from the left (equivalent to <Fade direction="left">...</Fade>
).
Other Props
You can also pass these props to Reveal
:
cascade
damping
delay
duration
fraction
triggerOnce
className
andchildClassName
style
andchildStyle
onVisibilityChange
Intersection Observer
Intersection Observer is the API used to determine if an element is inside the viewport or not. Browser support is really good – with Safari adding support in 12.1, all major browsers now support Intersection Observers natively.
If you need to support old browsers, add the polyfill for the Intersection Observer API.
Polyfill
You can add the polyfill directly or use a service like polyfill.io to add it when needed.
1yarn add intersection-observer
Then import it in your app:
1import "intersection-observer";
If you are using Webpack (or similar) you could use dynamic imports to load the polyfill only if needed. A basic implementation could look something like this:
1/** 2 * Do feature detection, to figure out which polyfills needs to be imported. 3 **/ 4async function loadPolyfills() { 5 if (typeof window.IntersectionObserver === "undefined") { 6 await import("intersection-observer"); 7 } 8}
Past Releases
To see the documentation for previous versions, navigate through past tags in the GitHub's project repository and read the README for that specific version.
License
Project source code is licensed under the MIT license. You are free to fork this repository, edit the code, share and use it both for non-commercial and commercial purposes.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No security vulnerabilities found.
Other packages similar to react-awesome-reveal
@plasmicpkgs/react-awesome-reveal
Plasmic registration call for react-awesome-reveal
aesthetic-accordion
This is An accordion UI component used to display a list of items, each of which can be expanded or collapsed to reveal or hide associated content.
react-awesome-reveal-triggerfix
React components to add reveal animations using the Intersection Observer API and CSS Animations.
@gioxxy/react-awesome-reveal
React components to add reveal animations using the Intersection Observer API and CSS Animations.