Convert Figma logo to code with AI

michaelvillar logodynamics.js

Javascript library to create physics-based animations

7,571
414
7,571
9

Top Related Projects

49,575

JavaScript animation engine

19,483

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

🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.

JavaScript/TypeScript animation engine

18,361

The motion graphics toolbelt for the web

A simple library to take care of complicated animations.

Quick Overview

Dynamics.js is a JavaScript library that simulates spring animations for smoother and more realistic UI interactions. It provides a simple API to create physics-based animations, allowing developers to easily implement natural-feeling motion in web applications.

Pros

  • Easy to use API for creating spring animations
  • Lightweight and dependency-free
  • Supports both DOM and non-DOM animations
  • Customizable spring parameters for fine-tuning animations

Cons

  • Limited to spring-based animations only
  • May require additional performance optimization for complex animations
  • Documentation could be more comprehensive
  • Not actively maintained (last update was in 2015)

Code Examples

Basic animation:

var el = document.getElementById('box');
dynamics.animate(el, {
  translateX: 100,
  scale: 1.2
}, {
  type: dynamics.spring,
  frequency: 200,
  friction: 200,
  duration: 1500
});

Chaining animations:

dynamics.animate(el, {
  translateX: 100
}, {
  type: dynamics.spring,
  complete: function() {
    dynamics.animate(el, {
      scale: 1.5
    }, {
      type: dynamics.easeInOut,
      duration: 500
    });
  }
});

Non-DOM animation:

var value = { x: 0 };
dynamics.animate(value, {
  x: 100
}, {
  type: dynamics.spring,
  change: function(v) {
    console.log('Current value:', v.x);
  }
});

Getting Started

  1. Include the dynamics.js script in your HTML:
<script src="https://cdnjs.cloudflare.com/ajax/libs/dynamics.js/1.1.5/dynamics.min.js"></script>
  1. Use the dynamics.animate() function to animate elements:
var element = document.querySelector('.my-element');
dynamics.animate(element, {
  translateX: 100,
  rotate: 45
}, {
  type: dynamics.spring,
  duration: 1000,
  friction: 300
});

This will animate the element 100 pixels to the right and rotate it 45 degrees using a spring animation.

Competitor Comparisons

49,575

JavaScript animation engine

Pros of Anime

  • More comprehensive feature set, including SVG animations and timeline control
  • Lighter weight and better performance, especially for complex animations
  • Active development and larger community support

Cons of Anime

  • Steeper learning curve due to more advanced features
  • Less focus on physics-based animations compared to Dynamics.js

Code Comparison

Dynamics.js:

dynamics.animate(element, {
  translateX: 100,
  scale: 2
}, {
  type: dynamics.spring,
  duration: 1000
});

Anime:

anime({
  targets: element,
  translateX: 100,
  scale: 2,
  easing: 'spring(1, 80, 10, 0)',
  duration: 1000
});

Key Differences

  • Anime offers a more flexible API with chainable methods and timeline support
  • Dynamics.js focuses on spring physics, while Anime provides a wider range of easing functions
  • Anime has better documentation and examples, making it easier for beginners to get started

Use Cases

  • Choose Dynamics.js for simpler, physics-based animations with a focus on natural motion
  • Opt for Anime when working on complex projects requiring diverse animation types and fine-grained control

Community and Maintenance

  • Anime has a larger user base and more frequent updates
  • Dynamics.js has fewer recent updates but remains a solid choice for specific use cases
19,483

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

Pros of GSAP

  • More comprehensive animation toolkit with a wider range of features
  • Better performance for complex animations and large-scale projects
  • Extensive documentation and community support

Cons of GSAP

  • Larger file size and potentially steeper learning curve
  • Requires a license for commercial use (free for personal projects)

Code Comparison

dynamics.js:

dynamics.animate(element, {
  translateX: 100,
  scale: 2
}, {
  type: dynamics.spring,
  duration: 1000
});

GSAP:

gsap.to(element, {
  x: 100,
  scale: 2,
  duration: 1,
  ease: "elastic"
});

Key Differences

  • dynamics.js focuses on physics-based animations, while GSAP offers a broader range of animation types
  • GSAP provides more advanced timeline and sequencing capabilities
  • dynamics.js is lightweight and free for all uses, making it suitable for smaller projects
  • GSAP has better browser compatibility and performance optimizations

Use Cases

  • dynamics.js: Ideal for simple, physics-based animations in small to medium-sized projects
  • GSAP: Better suited for complex animations, large-scale applications, and professional projects requiring advanced features

🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.

Pros of Animate.css

  • Simpler to use with predefined CSS classes
  • Lightweight and easy to integrate into existing projects
  • Extensive collection of ready-to-use animations

Cons of Animate.css

  • Less flexibility for custom animations
  • Limited control over animation timing and easing
  • Requires additional JavaScript for more complex animations

Code Comparison

Animate.css:

<div class="animate__animated animate__bounce">
  An animated element
</div>

Dynamics.js:

dynamics.animate(element, {
  translateY: 100,
  scale: 1.2
}, {
  type: dynamics.bounce,
  duration: 800
})

Summary

Animate.css is ideal for quick, predefined animations with minimal setup, while Dynamics.js offers more control and customization for complex animations. Animate.css uses CSS classes for simplicity, whereas Dynamics.js provides a JavaScript API for dynamic animations. Choose Animate.css for ease of use and lightweight implementation, or Dynamics.js for advanced, programmatic control over animations.

JavaScript/TypeScript animation engine

Pros of Tween.js

  • More comprehensive and feature-rich animation library
  • Supports a wider range of easing functions
  • Better documentation and community support

Cons of Tween.js

  • Larger file size and potentially higher overhead
  • May be overkill for simple animations
  • Less focus on physics-based animations

Code Comparison

Dynamics.js:

dynamics.animate(element, {
  translateX: 100,
  scale: 2
}, {
  type: dynamics.spring,
  duration: 1000
});

Tween.js:

new TWEEN.Tween(element.position)
  .to({ x: 100 }, 1000)
  .easing(TWEEN.Easing.Elastic.Out)
  .start();

Summary

Tween.js offers a more comprehensive animation solution with a wider range of features and easing functions. It has better documentation and community support, making it easier to use for complex projects. However, this comes at the cost of a larger file size and potentially higher overhead.

Dynamics.js, on the other hand, is more focused on physics-based animations and has a smaller footprint. It may be a better choice for simpler projects or when performance is a critical factor.

The code comparison shows that Dynamics.js has a more concise syntax for basic animations, while Tween.js offers more granular control over individual properties.

18,361

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
  • Active development and community support

Cons of mojs

  • Steeper learning curve due to more complex API
  • Larger file size, which may impact page load times

Code Comparison

dynamics.js:

dynamics.animate(element, {
  translateX: 100,
  scale: 2
}, {
  type: dynamics.spring,
  duration: 1000
});

mojs:

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

Key Differences

  • dynamics.js focuses on simple, physics-based animations
  • mojs offers more advanced features for complex animations and effects
  • dynamics.js has a simpler API, while mojs provides more customization options

Use Cases

  • dynamics.js: Ideal for basic UI animations and transitions
  • mojs: Better suited for creating intricate, eye-catching animations and interactive graphics

Community and Maintenance

  • dynamics.js: Less active development, smaller community
  • mojs: More active development and larger community support

A simple library to take care of complicated animations.

Pros of Choreographer-js

  • More flexible animation sequencing and chaining
  • Supports complex, multi-step animations
  • Easier to create reusable animation sequences

Cons of Choreographer-js

  • Steeper learning curve due to more complex API
  • Less focus on physics-based animations
  • Smaller community and fewer resources available

Code Comparison

Dynamics.js:

dynamics.animate(element, {
  translateX: 100,
  scale: 2
}, {
  type: dynamics.spring,
  duration: 1000
});

Choreographer-js:

const choreographer = new Choreographer({
  animations: [
    {
      range: [0, 100],
      selector: element,
      type: 'scale',
      style: 'transform',
      from: 1,
      to: 2
    }
  ]
});
choreographer.runAnimations();

Dynamics.js focuses on simple, physics-based animations with an easy-to-use API. It's great for quick, natural-looking animations but may be limited for complex sequences.

Choreographer-js offers more control over animation sequences and timing, allowing for intricate multi-step animations. However, it requires more setup and has a steeper learning curve.

Both libraries have their strengths, and the choice depends on the specific animation needs of your project.

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

Dynamics.js

Dynamics.js is a JavaScript library to create physics-based animations

To see some demos, check out dynamicsjs.com.

Usage

Download:

Include dynamics.js into your page:

<script src="dynamics.js"></script>

You can animate CSS properties of any DOM element.

var el = document.getElementById("logo")
dynamics.animate(el, {
  translateX: 350,
  scale: 2,
  opacity: 0.5
}, {
  type: dynamics.spring,
  frequency: 200,
  friction: 200,
  duration: 1500
})

You also can animate SVG properties.

var path = document.querySelector("path")
dynamics.animate(path, {
  d: "M0,0 L0,100 L100,50 L0,0 Z",
  fill: "#FF0000",
  rotateZ: 45,
  // rotateCX and rotateCY are the center of the rotation
  rotateCX: 100,
  rotateCY: 100
}, {
  friction: 800
})

And any JavaScript object.

var o = {
  number: 10,
  color: "#FFFFFF",
  string: "10deg",
  array: [ 1, 10 ]
}
dynamics.animate(o, {
  number: 20,
  color: "#000000",
  string: "90deg",
  array: [-9, 99 ]
})

Reference

dynamics.animate(el, properties, options)

Animates an element to the properties with the animation options.

  • el is a DOM element, a JavaScript object or an Array of elements
  • properties is an object of the properties/values you want to animate
  • options is an object representing the animation
    • type is the animation type: dynamics.spring, dynamics.easeInOut,... (default: dynamics.easeInOut)
    • frequency, friction, bounciness,... are specific to the animation type you are using
    • duration is in milliseconds (default: 1000)
    • delay is in milliseconds (default: 0)
    • complete (optional) is the completion callback
    • change (optional) is called at every change. Two arguments are passed to the function. function(el, progress)
      • el is the element it's animating
      • progress is the progress of the animation between 0 and 1

dynamics.stop(el)

Stops the animation applied on the element

dynamics.css(el, properties)

This is applying the CSS properties to your element with the correct browser prefixes.

  • el is a DOM element
  • properties is an object of the CSS properties

dynamics.setTimeout(fn, delay)

Dynamics.js has its own setTimeout. The reason is that requestAnimationFrame and setTimeout have different behaviors. In most browsers, requestAnimationFrame will not run in a background tab while setTimeout will. This can cause a lot of problems while using setTimeout along your animations. I suggest you use Dynamics's setTimeout and clearTimeout to handle these scenarios.

  • fn is the callback
  • delay is in milliseconds

Returns a unique id

dynamics.clearTimeout(id)

Clears a timeout that was defined earlier

  • id is the timeout id

dynamics.toggleSlow()

Toggle a debug mode to slow down every animations and timeouts. This is useful for development mode to tweak your animation. This can be activated using Shift-Control-D in the browser.

Dynamics and properties

dynamics.spring

  • frequency default is 300
  • friction default is 200
  • anticipationSize (optional)
  • anticipationStrength (optional)

dynamics.bounce

  • frequency default is 300
  • friction default is 200

dynamics.forceWithGravity and dynamics.gravity

  • bounciness default is 400
  • elasticity default is 200

dynamics.easeInOut, dynamics.easeIn and dynamics.easeOut

  • friction default is 500

dynamics.linear

No properties

dynamics.bezier

  • points array of points and control points

The easiest way to output this kind of array is to use the curve creator. Here is an example:

[{"x":0,"y":0,"cp":[{"x":0.2,"y":0}]},
 {"x":0.5,"y":-0.4,"cp":[{"x":0.4,"y":-0.4},{"x":0.8,"y":-0.4}]},
 {"x":1,"y":1,"cp":[{"x":0.8,"y":1}]}]

Contributing

Compile: npm run build or npm run build:watch

Run tests: npm test

Browser Support

Working on

  • Safari 7+
  • Firefox 35+
  • Chrome 34+
  • IE10+

Sylvester

Some code from Sylvester.js has been used (part of Vector and Matrix).

License

The MIT License (MIT)

Copyright (c) 2015 Michael Villar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

NPM DownloadsLast 30 Days