diff --git a/docs/content/3.api/2.use-spring.md b/docs/content/3.api/2.use-spring.md index 665a3440..d47e24cc 100644 --- a/docs/content/3.api/2.use-spring.md +++ b/docs/content/3.api/2.use-spring.md @@ -1,8 +1,10 @@ # useSpring -useSpring is a simpler hook than [useMotion](/api/use-motion). +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. -It has been implemented in order for you to implement Spring animations in your apps, without the pain. +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. + +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. useSpring can be bound to a HTML or SVG element, or to a simple object. @@ -10,21 +12,23 @@ It skips the [Variants](/features/variants) system, allowing it to be as perform ## Parameters -### `target` +### `values` -Target can be an element (**SVG** / **HTML**), or an object. +The values argument expects a `motionProperties` object, which can be created using the [useMotionProperties](/api/use-motion-properties) function. ### `spring` -The spring argument takes a [Spring definition](https://popmotion.io/#quick-start-animation-animate-spring-options) from **Popmotion**. +Spring animations can be configured in multiple ways, using spring options. The most intuitive way is using `duration` and `bounce`. Alternatively, you can use `stiffness`, `mass`, and `damping` to configure a spring animation. -It is optional as a default Spring will be applied if you do not specify it. +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. + +Passing a `string` argument is optional. A default spring will be applied if you do not specify it. ## Exposed ### `values` -Values are an object representing the current state from your Spring animations. +Values are an object representing the current state from your spring animations. ### `set` @@ -36,27 +40,54 @@ Stop is a function allowing you to stop all the ongoing animations for the sprin ## Example -```typescript -const target = ref() +In the example below, click the green box to animate it, or press the escape key to stop the animation. + +```html + -const { set, values, stop } = useSpring(target, { - damping: 50, - stiffness: 220, + + + + ```