You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 🦔 Tiny size ([~3.8KB gzipped](https://bundlephobia.com/result?p=@wellyshen/use-web-animations)). No external dependencies, aside for the `react`.
38
38
39
39
## Requirement
40
40
@@ -129,7 +129,22 @@ const App = () => {
129
129
};
130
130
```
131
131
132
-
> 💡 By default, the hook will be updated when options changed (i.e. keyframes, animationOptions etc.). However, you can disable the behavior by setting the `shouldUpdateAnimation` option to `false`.
132
+
### Setting/Updating Animation
133
+
134
+
The `keyframes` and `animationOptions` are cached when the hook is mounted. However, we can set/update the animation by the `animation` method.
@@ -528,24 +543,24 @@ It's returned with the following properties.
528
543
|`ref`| object || Used to set the target element for animating. |
529
544
|`playState`| string || Describes the playback state of an animation. |
530
545
|`getAnimation`| function || Access the [animation instance](https://developer.mozilla.org/en-US/docs/Web/API/Animation) for [playback control](#playback-control), [animation's information](#getting-animations-information) and more. |
531
-
|`animate`| function ||Creates animation at the `animationOptions` you want. Useful for [interactive animations and composite animations](#dynamic-interactions-with-animation).|
546
+
|`animate`| function ||Imperatively [set/update the animation](#settingupdating-animation). Useful for [interactive animations and composite animations](#dynamic-interactions-with-animation). |
532
547
533
548
### Parameter
534
549
535
550
The `options` provides the following configurations and event callbacks for you.
|`ref`| object || For [some reasons](#use-your-own-ref), you can pass in your own ref instead of using the built-in.|
540
-
|`id`| string |`""`| Sets the ID of an animation, implemented based on the [Animation.id](https://developer.mozilla.org/en-US/docs/Web/API/Animation/id).|
541
-
|`playbackRate`| number |`1`| Sets the playback rate of an animation, implemented based on the [Animation.playbackRate](https://developer.mozilla.org/en-US/docs/Web/API/Animation/playbackRate).|
542
-
|`autoPlay`| boolean |`true`| Automatically starts the animation.|
543
-
|`keyframes`| Array \| object || An array of keyframe objects, or a keyframe object whose property are arrays of values to iterate over. See [basic usage](#basic-usage) for more details.|
544
-
|`animationOptions`| number \| object || An **integer** representing the animation's duration (in milliseconds), or an **object** containing one or more timing properties. See [basic usage](#basic-usage) for more details.|
545
-
|`shouldUpdateAnimation`| boolean |`true`| By default, the hook will be updated when options changed (i.e. keyframes, animationOptions etc.). However, you can disable the behavior by setting this option to `false`. |
546
-
|`onReady`| function || It's invoked when an animation is ready to play. You can access the [playState](#basic-usage), [animate](#dynamic-interactions-with-animation) and [animation](#getting-animations-information) from the event object.|
547
-
|`onUpdate`| function || It's invoked when an animation enters the `running` state or changes state. You can access the [playState](#basic-usage), [animate](#dynamic-interactions-with-animation) and [animation](#getting-animations-information) from the event object. |
548
-
|`onFinish`| function || It's invoked when an animation enters the `finished` state. You can access the [playState](#basic-usage), [animate](#dynamic-interactions-with-animation) and [animation](#getting-animations-information) from the event object.|
|`ref`| object || For [some reasons](#use-your-own-ref), you can pass in your own ref instead of using the built-in. |
555
+
|`id`| string |`""`| Sets the ID of an animation, implemented based on the [Animation.id](https://developer.mozilla.org/en-US/docs/Web/API/Animation/id). |
556
+
|`playbackRate`| number |`1`| Sets the playback rate of an animation, implemented based on the [Animation.playbackRate](https://developer.mozilla.org/en-US/docs/Web/API/Animation/playbackRate). |
557
+
|`autoPlay`| boolean |`true`| Automatically starts the animation. |
558
+
|`keyframes`| Array \| object || An array of keyframe objects, or a keyframe object whose property are arrays of values to iterate over. See [basic usage](#basic-usage) for more details. |
559
+
|`animationOptions`| number \| object || An **integer** representing the animation's duration (in milliseconds), or an **object** containing one or more timing properties. See [basic usage](#basic-usage) for more details. |
560
+
561
+
|`onReady`| function || It's invoked when an animation is ready to play. You can access the [playState](#basic-usage), [animate](#dynamic-interactions-with-animation) and [animation](#getting-animations-information) from the event object. |
562
+
|`onUpdate`| function || It's invoked when an animation enters the `running` state or changes state. You can access the [playState](#basic-usage), [animate](#dynamic-interactions-with-animation) and [animation](#getting-animations-information) from the event object. |
563
+
|`onFinish`| function || It's invoked when an animation enters the `finished` state. You can access the [playState](#basic-usage), [animate](#dynamic-interactions-with-animation) and [animation](#getting-animations-information) from the event object. |
0 commit comments