Animation Functions

Composition-API-friendly functions to support model-based API

Spring

The primary animation component, which is a spring-physics based. Its main role is to move property from one value to another, with more natural animation and easing.

Using

spring function task SpringValue as its first argument, and SpringProps optional as the second argument.

Single Value

import { spring } from 'vue3-spring';

export default {
  name: 'App',
  setup() {
    // If you passed to the spring a number as it's value
    // it return a Vue ref object.
    const mySpring = spring(100 /* [, config] */);

    // To update the spring desired value
    mySpring.value = 200;

    return { mySpring };
  },
};

Multiple Values

import { spring } from 'vue3-spring';

export default {
  name: 'App',
  setup() {
    // If you passed to the spring an object of values
    // it return a Vue reactive object, for those values
    const mySpring = spring({ x: 100, y: 20 }, { dumping: 5 });

    // To update the spring desired values
    mySpring.x = 200;
    mySpring.y = -10;

    return { mySpring };
  },
};

Reactive Values

spring also accepts Vue reactive data type (reactive, ref) as its value. It will automatically update the current spring value, when the reactive values changed.

import { ref, reactive } from 'vue';
import { spring } from 'vue3-spring';

export default {
  setup() {
    const mouse = reactive({ x: 0, y: 0 });
    const mouseSpring = spring(mouse);

    // this will update mouseSpring as well
    mouse.x = 5;

    const singleValue = ref(0);
    const singleValueSpring = spring(singleValue);

    // this will update singleValueSpring as well
    singleValue.value = 5;

    return {
      mouseSpring,
    };
  },
};

Spring Props

To config the spring physical properties, and initial values

proptypedefaultdescription
fromnumber | object0init value
stiffnessnumber170spring stiffness, in kg / s^2
dampingnumber26damping constant, in kg / s
massnumber1spring mass
velocitynumber0initial velocity
precisionnumber2number of digits to round the values, increase the number to increase precision
framesPerSecondnumber60display refresh rate
isPendulumbooleanfalseis the animation will start agin after is dumped

Spring Value

Spring value could be number, object, Vue reactive object, or Vue ref object.

typereturn typeauto updatemultiple values
numberreffalsefalse
objectreactivefalsetrue
refreftruefalse
reactivereactivetruetrue

Parallax

Used move property from one value to another, based on the scrolled distance.

COMING SOON

Present

Used to apply CSS animation class to an element, when it enters the view-port.

COMING SOON