Spring

A draggable element tied to its place by a spring coil, which pulls it back on release.

<script setup lang="ts">
import { Spring, SpringElement, SpringProvider } from '@animate-ui/vue/primitives/spring'
</script>

<template>
  <SpringProvider>
    <Spring class="z-10 text-muted-foreground" />
    <SpringElement class="relative z-20">
      <div
        aria-label="Drag me"
        class="flex size-14 items-center justify-center rounded-full bg-primary text-sm font-medium text-primary-foreground shadow-md select-none"
      >
        Drag
      </div>
    </SpringElement>
  </SpringProvider>
</template>

Installation

npm install @animate-ui/vue motion-v
pnpm add @animate-ui/vue motion-v
yarn add @animate-ui/vue motion-v
bun add @animate-ui/vue motion-v

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.
  • Spring is 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

PropTypeDefault
transition?
SpringOptions{ stiffness: 200, damping: 16 }
path-config?
SpringPathConfig{}
#default
slot-

SpringPathConfig

PropTypeDefault
coil-count?
number8
amplitude-min?
number8
amplitude-max?
number20
curve-ratio-min?
number0.5
curve-ratio-max?
number1
bezier-offset?
number8

Spring

The coil. Its color is currentColor.

PropTypeDefault
...props?
SVGAttributes-

SpringElement

PropTypeDefault
as-child?
booleanfalse
#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.

Credits

Built by Skyleen. The source code is available on GitHub.

Last updated: 10/23/2026