Socket
Socket
Sign inDemoInstall

@tweenjs/tween.js

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tweenjs/tween.js

Simple and fast tweening engine with optimised Robert Penner's equations.


Version published
Weekly downloads
479K
decreased by-15.98%
Maintainers
4
Weekly downloads
 
Created

What is @tweenjs/tween.js?

@tweenjs/tween.js is a simple but powerful tweening engine for JavaScript. It allows you to create smooth animations by interpolating between values over time. This can be used for animating properties of objects, such as position, scale, rotation, and more.

What are @tweenjs/tween.js's main functionalities?

Basic Tweening

This code demonstrates basic tweening where an object's properties (x and y coordinates) are animated from one state to another over a duration of 1000 milliseconds.

const TWEEN = require('@tweenjs/tween.js');

let coords = { x: 0, y: 0 };
let tween = new TWEEN.Tween(coords)
  .to({ x: 100, y: 100 }, 1000)
  .onUpdate(() => {
    console.log(coords);
  })
  .start();

function animate(time) {
  requestAnimationFrame(animate);
  TWEEN.update(time);
}

requestAnimationFrame(animate);

Easing Functions

This code demonstrates the use of easing functions to create more natural motion. The Quadratic.Out easing function is used to slow down the animation towards the end.

const TWEEN = require('@tweenjs/tween.js');

let coords = { x: 0, y: 0 };
let tween = new TWEEN.Tween(coords)
  .to({ x: 100, y: 100 }, 1000)
  .easing(TWEEN.Easing.Quadratic.Out)
  .onUpdate(() => {
    console.log(coords);
  })
  .start();

function animate(time) {
  requestAnimationFrame(animate);
  TWEEN.update(time);
}

requestAnimationFrame(animate);

Chaining Tweens

This code demonstrates chaining tweens, where one tween starts after another finishes. The x coordinate is animated first, followed by the y coordinate.

const TWEEN = require('@tweenjs/tween.js');

let coords = { x: 0, y: 0 };
let tween1 = new TWEEN.Tween(coords)
  .to({ x: 100 }, 1000);
let tween2 = new TWEEN.Tween(coords)
  .to({ y: 100 }, 1000);

tween1.chain(tween2);
tween1.start();

function animate(time) {
  requestAnimationFrame(animate);
  TWEEN.update(time);
}

requestAnimationFrame(animate);

Other packages similar to @tweenjs/tween.js

Keywords

FAQs

Package last updated on 14 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc