useSpring
useSpring
creates a motion value that will animate to its latest target with a spring animation.
The target can either be set manually via .set
, or automatically by passing in another motion value.
Usage
Import useSpring
from Motion Vue:
Direct control
useSpring can be created with a number, or a unit-type (px, % etc) string:
Now, whenever this motion value is updated via set()
, the value will animate to its new target with the defined spring.
It's also possible to update this value immediately, without a spring, with the jump()
method.
Track another motion value
Its also possible to automatically spring towards the latest value of another motion value:
This source motion value must also be a number, or unit-type string.
Options
The spring can be configured with a number of options. For whole reference, refer to motion's docs.
damping
Default: 10
Strength of opposing force. If set to 0, spring will oscillate indefinitely.
mass
Default: 1
Mass of the moving object. Higher values will result in more lethargic movement.
stiffness
Default: 1
Stiffness of the spring. Higher values will create more sudden movement.