1.2.0 • Published 2 years ago

reactanimationonscreen v1.2.0

Weekly downloads
14
License
MIT
Repository
-
Last release
2 years ago

React Animation On Screen

React Animation On Screen is a custom React hook to check when an element is appearing on the screen and apply some animation to it.

NPM JavaScript Style Guide

Installation

npm install reactanimationonscreen

Usage

Initiate the function inside an useEffect passing an array of classnames you want to apply the animation, an array of css classes with the animations to be applied.

import useOnScreen from "reactanimationonscreen";

useEffect(() => {
  const sections = useOnScreen(targetClassNames: string[], animationClassNames: string[]);
}, []);

Example

import useOnScreen from "reactanimationonscreen";

useEffect(() => {
  const sections = useOnScreen(
    ["subtitle", "paragraph"],
    ["subtitleAnimation", "paragraphAnimation"]
  );
}, []);

Extra Feature 1

By default the animation is applied when the target starts to appear on the bottom of the screen but if you want the animation to be applied later you can pass a third argument to the function call.

The example below only applies the animation when the target is 250px above the bottom of the screen.

import useOnScreen from "reactanimationonscreen";

useEffect(() => {
  const sections = useOnScreen(["title"], ["titleAnimation"], 250);
}, []);

Extra Feature 2

By default the animation is applied only the first time the target appears on the viewport, but if you want the animation to be applied everytime the target enters the viewport pass a boolean true value as the fourth argument to the function call.

import useOnScreen from "reactanimationonscreen";

useEffect(() => {
  const sections = useOnScreen(["title"], ["titleAnimation"], 250, true);
}, []);
1.2.0

2 years ago

1.1.0

3 years ago

1.0.0

3 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago