Convert Figma logo to code with AI

jeremyckahn logoshifty

The fastest TypeScript animation engine on the web

1,538
88
1,538
0

Top Related Projects

19,483

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

49,575

JavaScript animation engine

JavaScript/TypeScript animation engine

3,556

A simple but powerful tweening / animation library for Javascript. Part of the CreateJS suite of libraries.

18,496

The motion graphics toolbelt for the web

Quick Overview

Shifty is a lightweight JavaScript animation library that provides a simple API for creating and managing tweens. It allows developers to animate CSS properties, DOM attributes, and JavaScript object properties with ease, offering a flexible and performant solution for web animations.

Pros

  • Lightweight and fast, with minimal dependencies
  • Supports both CSS and JavaScript-based animations
  • Provides easing functions and custom easing support
  • Offers a chainable API for creating complex animation sequences

Cons

  • Limited documentation and examples compared to larger animation libraries
  • Lacks some advanced features found in more comprehensive animation frameworks
  • May require additional plugins or extensions for certain complex animations
  • Not as widely adopted as some other popular animation libraries

Code Examples

Creating a simple tween:

const tween = Tweenable.tween({
  from: { x: 0, y: 0 },
  to: { x: 100, y: 100 },
  duration: 1000,
  easing: 'easeInOutQuad',
  step: (state) => {
    console.log(`x: ${state.x}, y: ${state.y}`);
  }
});

Chaining multiple tweens:

Tweenable.tween({
  from: { x: 0 },
  to: { x: 100 },
  duration: 1000
})
.then({
  to: { x: 0 },
  duration: 1000
})
.then({
  to: { x: 200 },
  duration: 1000
});

Using a custom easing function:

Tweenable.tween({
  from: { scale: 1 },
  to: { scale: 2 },
  duration: 1000,
  easing: (t) => t * t * t, // Custom cubic easing function
  step: (state) => {
    console.log(`Scale: ${state.scale}`);
  }
});

Getting Started

To use Shifty in your project, first install it via npm:

npm install shifty

Then, import and use it in your JavaScript code:

import { Tweenable } from 'shifty';

const tween = Tweenable.tween({
  from: { opacity: 0 },
  to: { opacity: 1 },
  duration: 1000,
  step: (state) => {
    document.getElementById('myElement').style.opacity = state.opacity;
  }
});

This example creates a simple fade-in animation for an element with the ID 'myElement'.

Competitor Comparisons

19,483

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

Pros of GSAP

  • More comprehensive animation toolkit with advanced features like timelines and plugins
  • Larger community and ecosystem, with extensive documentation and examples
  • Better performance, especially for complex animations

Cons of GSAP

  • Larger file size and potentially steeper learning curve
  • Commercial license required for some use cases
  • More opinionated API, which may not suit all project styles

Code Comparison

Shifty:

var tween = new Tweenable();
tween.tween({
  from: { x: 0 },
  to: { x: 100 },
  duration: 1000,
  easing: 'easeInOutQuad'
});

GSAP:

gsap.to("#myElement", {
  x: 100,
  duration: 1,
  ease: "power2.inOut"
});

Summary

Shifty is a lightweight tweening engine focused on simplicity and flexibility. It's ideal for projects that require basic animations and prefer a smaller footprint.

GSAP is a more powerful and feature-rich animation library, offering advanced capabilities and better performance for complex animations. It's well-suited for projects that demand sophisticated animation sequences and can benefit from its extensive ecosystem.

The choice between the two depends on the project's specific requirements, complexity of animations needed, and performance considerations.

49,575

JavaScript animation engine

Pros of anime

  • Larger community and more frequent updates
  • Supports a wider range of animation properties
  • Offers more advanced features like timeline and playback control

Cons of anime

  • Larger file size, which may impact load times
  • Steeper learning curve due to more complex API
  • May be overkill for simple animations

Code Comparison

anime:

anime({
  targets: '.element',
  translateX: 250,
  rotate: '1turn',
  duration: 800,
  easing: 'easeInOutQuad'
});

shifty:

var tweenable = new Tweenable();
tweenable.tween({
  from: { x: 0, rotation: 0 },
  to: { x: 250, rotation: 360 },
  duration: 800,
  easing: 'easeInOutQuad'
});

Both libraries allow for smooth animations with easing functions, but anime provides a more concise syntax and built-in support for CSS transforms. Shifty requires manual updating of element properties, while anime handles this automatically.

anime is generally more feature-rich and widely adopted, making it suitable for complex animations and projects requiring extensive animation capabilities. Shifty, on the other hand, is lighter and may be preferable for simpler use cases or projects where minimizing file size is crucial.

JavaScript/TypeScript animation engine

Pros of tween.js

  • More comprehensive documentation and examples
  • Wider community adoption and longer development history
  • Built-in support for color tweening and string interpolation

Cons of tween.js

  • Larger file size and potentially higher overhead
  • Less modular architecture compared to Shifty's plugin system
  • Fewer easing functions available out-of-the-box

Code Comparison

Shifty:

var tween = new Tweenable();
tween.tween({
  from: { x: 0 },
  to: { x: 100 },
  duration: 1000,
  easing: 'easeInOutQuad',
  step: function (state) {
    console.log(state.x);
  }
});

tween.js:

var tween = new TWEEN.Tween({ x: 0 })
  .to({ x: 100 }, 1000)
  .easing(TWEEN.Easing.Quadratic.InOut)
  .onUpdate(function(object) {
    console.log(object.x);
  })
  .start();

Both libraries offer similar functionality for creating and managing tweens, with slight differences in syntax and API design. Shifty uses a more object-oriented approach, while tween.js employs a chaining method pattern. The choice between the two often depends on specific project requirements and personal preference.

3,556

A simple but powerful tweening / animation library for Javascript. Part of the CreateJS suite of libraries.

Pros of TweenJS

  • Part of the larger CreateJS suite, offering integration with other libraries
  • Extensive documentation and examples available
  • Supports complex animation sequences and timelines

Cons of TweenJS

  • Larger file size and potentially more overhead
  • Less focused on performance optimization compared to Shifty
  • May have a steeper learning curve for beginners

Code Comparison

Shifty:

const tween = new Tweenable();
tween.tween({
  from: { x: 0 },
  to: { x: 100 },
  duration: 1000,
  easing: 'easeInOutQuad',
  step: state => console.log(state.x)
});

TweenJS:

createjs.Tween.get(target)
  .to({ x: 100 }, 1000, createjs.Ease.quadInOut)
  .addEventListener("change", handleChange);

function handleChange(event) {
  console.log(target.x);
}

Both libraries provide similar functionality for creating tweens, but TweenJS uses a more object-oriented approach with its Tween.get() method and event listeners. Shifty's API is more functional and focuses on creating and managing individual tween instances. TweenJS offers more built-in features for complex animations, while Shifty prioritizes a lightweight and performant core with extensibility options.

18,496

The motion graphics toolbelt for the web

Pros of mojs

  • More comprehensive animation toolkit with a wider range of features
  • Supports complex shape animations and custom effects
  • Provides a visual timeline editor for easier animation creation

Cons of mojs

  • Steeper learning curve due to its extensive feature set
  • Larger file size, which may impact page load times
  • Less focused on pure tweening, as it covers a broader range of animation types

Code Comparison

mojs:

const burst = new mojs.Burst({
  radius:   { 0: 100 },
  count:    5,
  children: {
    shape:      'circle',
    fill:       { 'cyan' : 'yellow' },
    duration:   2000
  }
});

Shifty:

const tween = new Tweenable();
tween.tween({
  from: { x: 0, y: 0 },
  to: { x: 100, y: 100 },
  duration: 1000,
  easing: 'easeInOutQuad'
});

Summary

mojs is a more feature-rich animation library that offers complex shape animations and a visual editor, making it suitable for advanced animation projects. However, it comes with a steeper learning curve and larger file size. Shifty, on the other hand, focuses primarily on tweening and provides a simpler API for basic animations, making it more lightweight and easier to use for straightforward tweening tasks.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Shifty - The fastest TypeScript animation engine on the web

Current Shifty version

  • main: CI

Shifty is a tweening engine for TypeScript. It is a lightweight library meant to be encapsulated by higher level tools. At its core, Shifty provides:

  • Best-in-class animation performance
  • Playback control of an individual tween
  • Extensibility hooks for key points in the tween lifecycle
  • Promise support for async/await programming

This is useful because it is the least amount of functionality needed to build customizable animations. Shifty is optimized to run with the minimal processing and memory overhead.

import { tween } from 'shifty'
;(async () => {
  const element = document.querySelector('#tweenable')

  const { tweenable } = await tween({
    render: ({ scale, x }) => {
      element.style.transform = `translateX(${x}px) scale(${scale})`
    },
    easing: 'easeInOutQuad',
    duration: 500,
    from: { scale: 1, x: 0 },
    to: { x: 200 },
  })

  await tweenable.tween({
    to: { x: 0 },
  })

  await tweenable.tween({
    to: { scale: 3 },
  })
})()

Installation

npm install --save shifty

Environment compatibility

Shifty officially supports Evergreen browsers, Safari, and Node 10 and above. Internet Explorer is supported by v2 If you encounter a browser-specific bug, please open an issue about it!

Support this project!

Shifty is a labor of love that will always be free and open source. If you've gotten value out of Shifty, please consider supporting the developer with a small donation!

Developing Shifty

First, install the development dependencies via NPM:

npm ci

Once those are installed, you can generate dist/shifty.js with:

npm run build

To run the tests:

npm test

To generate the documentation (in dist/doc):

npm run doc

Loading Shifty

Shifty exposes a UMD module, so you can load it however you like:

// ES6
import { tween } from 'shifty'

Or:

// AMD
define(['shifty'], function(shifty) {
  shifty.tween({ from: { x: 0 }, to: { x: 10 } })
})

Or even:

// CommonJS
const { tween } = require('shifty')

tween({ from: { x: 0 }, to: { x: 10 } })

Using Shifty

See the Getting Started guide and check out the API documentation.

Troubleshooting

Jest

With later versions of Jest it is known that by default Shifty may cause warnings that look like:

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

To prevent this, use shouldScheduleUpdate in your test setup like so:

import { shouldScheduleUpdate } from 'shifty'

afterAll(() => {
  shouldScheduleUpdate(false)
})

Breaking changes

From v2 to v3

Shifty's legacy version 2 remains available in the v2 branch. Legacy documentation can be found at: https://shifty-git-v2-jeremyckahn.vercel.app/

  • Tweenable.formulas has been renamed to Tweenable.easing
  • tweenConfig.step has been removed in favor of tweenConfig.render (behavior and API is unchanged).
  • tweenConfig.attachment has been removed in favor of tweenConfig.data (behavior and API is unchanged).
  • Tweenable#tweenable has been removed.
  • Tweenable#set() is now Tweenable#setState.
  • Tweenable#get() is now Tweenable#state (a getter, not a method).
  • Tweenable#hasEnded() is now Tweenable#hasEnded (a getter, not a method).
  • Tweenable#isPlaying() is now Tweenable#isPlaying (a getter, not a method).
  • Tweenable#setScheduleFunction has been removed. The static method Tweenable.setScheduleFunction method should be used instead.
  • Render handler parameters have been reordered:
    • In v2, the function signature was (state: TweenState, data: Data, timeElapsed: number) => void
    • In v3, the function signature was (state: TweenState, timeElapsed: number, data: Data) => void
  • Scene#play() has been renamed to Scene#tween.
  • Scene#isPlaying() is now Scene#isPlaying (a getter, not a method).
  • Scene#playingTweenables() has been removed.
  • unsetBezierFunction has been removed.
  • Shifty "Core" build has been removed.

Non-breaking changes

  • Token extension is now baked into Shifty Core.

Contributors

Take a look at the Network page to see all of the Shifty contributors.

Special thanks goes to Thomas Fuchs: Shifty's easing functions and Bezier curve code was adapted from his awesome Scripty2 project.

License

Shifty is distributed under the MIT license. You are encouraged to use and modify the code to suit your needs, as well as redistribute it.

NPM DownloadsLast 30 Days