Gathering detailed insights and metrics for react-flip-tilt
Gathering detailed insights and metrics for react-flip-tilt
Gathering detailed insights and metrics for react-flip-tilt
Gathering detailed insights and metrics for react-flip-tilt
A Performant Customizable React Component Providing the Flip-Tilt Effect
npm install react-flip-tilt
Typescript
Module System
Node Version
NPM Version
66.9
Supply Chain
90.4
Quality
76
Maintenance
100
Vulnerability
100
License
TypeScript (98.11%)
JavaScript (1.17%)
HTML (0.72%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
23 Commits
1 Watchers
2 Branches
1 Contributors
Updated on Nov 24, 2024
Minified
Minified + Gzipped
Latest Version
0.2.0
Package Id
react-flip-tilt@0.2.0
Unpacked Size
238.70 kB
Size
45.76 kB
File Count
6
NPM Version
10.1.0
Node Version
20.8.0
Published on
Nov 07, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
3
29
A Performant Customizable React Component Providing the Flip-Tilt Effect
Main Demo • Main Demo (Parallax) • Flip Direction Demo • Control Element Demo • Storybook
1$ npm install framer-motion react-flip-tilt
Once the package is installed, you can import
the component:
1import { FlipTilt } from 'react-flip-tilt';
You can set the front
/back
properties to either an image source as string
or an element/component
1<FlipTilt front="/front.webp" back="/back.webp" />
1<FlipTilt front={<div>...</div>} back={<MyComponent />} />
1<FlipTilt front="/front.webp" back={<MyComponent />} />
This component is "parallax ready", meaning you don't need to change any settings for it to work.
You just need to set up your parallax effect in JSX/CSS and set it as the front/back element.
You can read this article to learn more about how to set up the 3D parallax effect.
Follow the usage guide on react-next-parallax
's readme.
Instead of placing your scene inside <Parallax></Parallax>
, set it as the front/back element.
All props are optional
In addition to these props, you can use:
- Any valid
HTMLDivElement
props likeclassName=''
,data-...='...'
,onMouseMove={...}
etc. they will be applied to the container element.- Any of the
react-next-tilt
props likescale
,disableScrollOnTouch
,controlElement
, etc.- Any of the
react-next-parallax
props likeanimationMode
,animationReverse
,offsetMultiplier
, etc. (whentype
is set to'parallax'
)
While you can flip the component by changing the
flipped
prop, it will cause the component to re-render and interrupts the animation. It is advised to use theflip()
function exposed by the component's ref instead.
Name | Description | Default |
---|---|---|
front | Front image/element note: You can pass either an image source as string or an element/component example: 'path/to/image.jpg', <div>...</div>, <Component /> ReactNode | <></> |
back | Back image/element note: You can pass either an image source as string or an element/component example: 'path/to/image.jpg', <div>...</div>, <Component /> ReactNode | <></> |
direction | Direction of the flip animation see the Flip Direction Demo "horizontal" | "vertical" | "horizontal" |
flipReverse | Reverses the rotation of the flip animation see the Flip Direction Demo boolean | false |
flipBackReverse | Reverses the rotation of the flip back animation see the Flip Direction Demo boolean | false |
borderWidth | Border width applied to the back image/element example: '4px', '1em', '2rem' string | "2px" |
borderColor | Border color applied to the back image/element example: 'lightblue', '#445566AA', 'rgba(50,150,250,0.5)', 'hsla(100,50%,50%,0.2)' string(Property.BorderColor) | white |
borderStyle | Border style applied to the back image/element example: 'solid', 'dashed', 'dotted' string (Property.BorderStyle) | solid |
mass | Mass of the element in framer-motion 's spring animation. Higher values will result in more lethargic movement.number | 0.5 |
stiffness | Stiffness of the spring in framer-motion 's spring animation. Higher values will create more sudden movement.number | 120 |
flipped | Locks the component to one side
boolean | - |
type | "tilt" | "parallax" | "tilt" |
The component has the following events/callbacks in addition to react-next-tilt
events/callbacks:
Name | Description | Parameters |
---|---|---|
onFlip | Callback function that is called with the container element when the component flips and the back side is visible (element: HTMLDivElement) => void | element : The component's container element |
onFlipBack | Callback function that is called with the container element when the component flips back and the front side is visible (element: HTMLDivElement) => void | element : The component's container element |
The component's ref object contains the following properties in addition to react-next-tilt
ref properties:
Name | Description | Parameters |
---|---|---|
isFlipped | Returns whether the element is flipped or not () => boolean | - |
flip | Animates/Flips the component without re-rendering it. () => Promise<void> | - |
1import { FlipTilt } from 'react-flip-tilt'; 2 3const MyComponent = () => { 4 return ( 5 <FlipTilt 6 ref={(ref) => { 7 if (ref) { 8 //do something with the ref 9 } 10 }} 11 ... 12 /> 13 ); 14};
1import { useRef, useEffect } from 'react'; 2import { FlipTilt, FlipTiltRef } from 'react-flip-tilt'; 3 4const MyComponent = () => { 5 const ref = useRef<FlipTiltRef>(null); 6 7 useEffect(() => { 8 if (ref.current) { 9 //do something with the ref 10 } 11 }, []); 12 13 return <FlipTilt ref={ref} ... />; 14};
1import { useRef, useEffect } from 'react'; 2import { FlipTilt, FlipTiltRef } from 'react-flip-tilt'; 3 4const MyComponent = () => { 5 const ref = useRef<FlipTiltRef | null>(null); 6 7 useEffect(()=>{ 8 if (ref.current) { 9 //do something else with the ref 10 } 11 },[]); 12 13 return ( 14 <FlipTilt 15 ref={async (r) => { 16 if (r) { 17 console.log(`isFlipped = ${r.isFlipped()}`); 18 await r.flip(); 19 console.log(`isFlipped = ${r.isFlipped()}`); 20 ref.current = r; 21 } 22 }} 23 ... 24 /> 25 ); 26};
Animated using framer-motion
Inspired by evolany.com
Rashid Shamloo (github.com/rashidshamloo)
No vulnerabilities found.
No security vulnerabilities found.