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
useSpring is a simpler hook than [useMotion](/api/use-motion).
3
+
useSpring is a simpler hook than [useMotion](/api/use-motion) and makes it possible to animate HTML or SVG Elements in your Vue components using spring animations.
4
4
5
-
It has been implemented in order for you to implement Spring animations in your apps, without the pain.
5
+
Spring animations often feel more natural and fluid compared to linear animations, as they are based on the physics of a spring in the real world.
6
+
7
+
Springs maintain continuity for both static cases and cases with an initial velocity. This allows spring animations to adapt smoothly to user interactions like gestures.
6
8
7
9
useSpring can be bound to a HTML or SVG element, or to a simple object.
8
10
9
11
It skips the [Variants](/features/variants) system, allowing it to be as performant as using Popmotion natively, but with a nicer **API** to play with Vue refs.
10
12
11
13
## Parameters
12
14
13
-
### `target`
15
+
### `values`
14
16
15
-
Target can be an element (**SVG** / **HTML**), or an object.
17
+
The values argument expects a `motionProperties` object, which can be created using the [useMotionProperties](/api/use-motion-properties) function.
16
18
17
19
### `spring`
18
20
19
-
The spring argument takes a [Spring definition](https://popmotion.io/#quick-start-animation-animate-spring-options) from **Popmotion**.
21
+
Spring animations can be configured in multiple ways, using springoptions. The most intuitive way is using `duration` and `bounce`. Alternatively, you can use `stiffness`, `mass`, and `damping` to configure a spring animation.
20
22
21
-
It is optional as a default Spring will be applied if you do not specify it.
23
+
Under the hood, `useSpring` uses **Popmotion**. See [Spring options in Popmotion](https://popmotion.io/#quick-start-animation-animate-spring-options) for a full list of spring options.
24
+
25
+
Passing a `string` argument is optional. A default spring will be applied if you do not specify it.
22
26
23
27
## Exposed
24
28
25
29
### `values`
26
30
27
-
Values are an object representing the current state from your Spring animations.
31
+
Values are an object representing the current state from your spring animations.
28
32
29
33
### `set`
30
34
@@ -36,27 +40,54 @@ Stop is a function allowing you to stop all the ongoing animations for the sprin
36
40
37
41
## Example
38
42
39
-
```typescript
40
-
const target =ref<HTMLElement>()
43
+
In the example below, click the green box to animate it, or press the escape key to stop the animation.
0 commit comments