Tween
The Tween component uses the gsap.to(), gsap.from() and gsap.fromTo() functions internally.
The children need to be "refable" components. So they can be HTML elements or forwardRef components like styled-components components.
import { Controls, PlayState, Tween } from 'react-gsap';
Use "to" prop
Use "from" prop
Use "from" and "to" prop
Internally the gsap.fromTo() function will be called.
Use stagger prop
If you have multiple children you can make use of the stagger prop.
More info: https://greensock.com/docs/v3/Staggers
Advanced stagger
Props
The question mark means it's an optional prop.
For a documentation of all possible props or from and to values check out the documentations: vars, gsap.to(), gsap.from() and gsap.fromTo()
Name | Type | Description |
---|---|---|
children? | React.ReactNode | Need to be "refable" components. So they can be HTML elements or forwardRef components like styled-components components |
wrapper? | any | This component gets wrapped around the Tween component |
target? | number | string | The target index or key of the Timeline targets. Used if Tween is childless and child of a Timeline |
position? | string | number | If this Tween is a child from a Timeline it's added at this position |
from? | any | The vars object for the gsap.from() or gsap.fromTo() function |
to? | any | The vars object for the gsap.to() or gsap.fromTo() function |
stagger? | number | Stagger | (index: number, target: any, list: any) => number | If multiple children are added, you can stagger the start times for each |
duration? | number | The duration of the animation (in seconds) (Can be changed on-the-fly) |
progress? | number | 0 - 1 (Can be changed on-the-fly) |
totalProgress? | number | 0 - 1 (Can be changed on-the-fly) |
playState? | PlayState | Use it to control the playing state (Can be changed on-the-fly) |
disabled? | boolean | on-the-fly changes and are no more possible |
onlyInvalidateTo? | boolean | |
[prop: string] | any | All other props are added to the vars object for the Tween functions |
Type Stagger
More info: https://greensock.com/docs/v3/Staggers
Name | Type |
---|---|
amount? | number |
each? | number |
from? | 'start' | 'center' | 'edges' | 'random' | 'end' | number | [number, number] |
grid? | [number, number] | 'auto' |
axis? | 'x' | 'y' |
ease? | string | (value: number) => number |
repeat? | number |
yoyo? | boolean |
[prop: string] | any |
Enum PlayState
Field | As string |
---|---|
play | "play" |
restart | "restart" |
reverse | "reverse" |
restartReverse | "restartReverse" |
stop | "stop" |
stopEnd | "stopEnd" |
pause | "pause" |
resume | "resume" |