eSpring

Hold-key based spring animations

Github Repo

v1.0.1

Initial release

js
spring();

Problem

Spring based animations are a great way to work quickly and get great looking animations, but existing solutions have some drawbacks:

  • Require copy pasting code into each expression
  • Require 2 keyframes for each value
  • Fail when animating out of an in-progress spring animation

The solution

Our library works by animating to each keyframe value, with the animation duration set by the spring configuration. This means only 1 keyframe is required for each value.

The spring function takes an object with the spring settings as it's only parameter.

js
spring({
mass: 1,
stiffness: 100,
damping: 10,
});

It also animates out of in progress animations correctly.

Usage

Import

Download the library .jsx file and import it into your After Effects project.

It's also a good idea to place the file in any compositions where it's used, so that After Effects will count it as used when reducing the project.

Reference the library

The library exposes the spring function.

js
const { spring } = footage("eSpring.jsx").sourceData;

Call the spring function

The function returns a value that animates to each keyframe on the property, starting at the time of the next keyframe in the series. The duration of each animation is based on the spring, so the resultant animation is always physically accurate.

js
spring();

Below is a rough diagram on the animation timings for the given keyframes.

js
// Keyframes
// ... [1] ... [2].... [3].....
// Animation
// ............[1-2]...[2-3]...

You can use this interactive demo to play around with different spring configurations and see how they influence the animation.

API

spring

function


ts
spring(springConfig: {
mass: number = 1,
stiffness: number = 100,
damping: number = 10,
initialVelocity: number = 0,
property: Property = thisProperty,
__fast: boolean = false,
}): PropertyValueType;

Parameters

  • mass: The mass of the "object" at the end of the spring. Higher values will move slower but take longer to come to rest
  • stiffness: Higher values will move to the next keyframe faster and be more bouncy
  • damping: Used to take energy out of the spring. Higher values will move slower and be less bouncy
  • initialVelocity: The velocity to animate out of the previous keyframe with
  • property The keyframed property to apply the spring animation to
  • __fast If true, the code to animate out of an in progress spring animation will be skipped, resulting in a faster but less accurate animation.

Checking the version

All of our libraries expose a version string you can use to check if it's up to date:

js
throw footage("lib.jsx").sourceData.version;
For enquiries contact us at hey@motiondeveloper.com