A draggable element tied to its place by a spring coil, which pulls it back on release.
Installation
Usage
<script setup lang="ts">
import { Spring, SpringElement, SpringProvider } from '@animate-ui/vue/primitives/spring';
</script>
<template>
<SpringProvider>
<Spring class="text-muted-foreground" />
<SpringElement>
<img src="/avatar.png" alt="Avatar" draggable="false" />
</SpringElement>
</SpringProvider>
</template>Add draggable="false" to images inside SpringElement, so the browser's
native drag image doesn't take over the drag.
Animation
- Dragging stretches a coil between the element's place and the element. The coil tightens as it stretches.
- On release, the element springs back with a bounce, the coil following it.
Springis a full-viewport SVG that never catches the pointer.- Under reduced motion, the element is back in place at once on release.
API Reference
SpringProvider
| Prop | Type | Default |
|---|---|---|
transition? | SpringOptions | { stiffness: 200, damping: 16 } |
path-config? | SpringPathConfig | {} |
#default | slot | - |
SpringPathConfig
| Prop | Type | Default |
|---|---|---|
coil-count? | number | 8 |
amplitude-min? | number | 8 |
amplitude-max? | number | 20 |
curve-ratio-min? | number | 0.5 |
curve-ratio-max? | number | 1 |
bezier-offset? | number | 8 |
Spring
The coil. Its color is currentColor.
| Prop | Type | Default |
|---|---|---|
...props? | SVGAttributes | - |
SpringElement
| Prop | Type | Default |
|---|---|---|
as-child? | boolean | false |
#default | slot | - |
...props? | HTMLMotionProps<'div'> | - |
useSpring
Returns the spring state: the x/y and springX/springY motion values, the isDragging ref, a path() getter for the coil and the child ref.