Scripts2026年7月23日·1 分钟阅读

Tween.js — JavaScript and TypeScript Animation Engine

A small, dependency-free tweening engine for smoothly interpolating numeric values over time, commonly used with Three.js and WebGL applications.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Tween.js Overview
直接安装命令
npx -y tokrepo@latest install 1d08c451-862e-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Tween.js is a tweening engine that smoothly transitions numeric properties from one value to another over a specified duration. It is widely used alongside Three.js for camera movements, object transitions, and procedural animations. The library handles easing, chaining, repeating, and grouping of tweens.

What Tween.js Does

  • Interpolates any numeric property on a JavaScript object over time
  • Provides 30+ built-in easing functions (Linear, Quadratic, Cubic, Elastic, Bounce, etc.)
  • Chains tweens sequentially so one starts when another ends
  • Supports repeat, yoyo (ping-pong), and delay for looping animations
  • Groups tweens for independent update cycles in complex scenes

Architecture Overview

Tween.js stores the start values, end values, duration, and easing function for each property being animated. On each call to TWEEN.update(time), it calculates the elapsed fraction, applies the easing function to get an interpolation factor, and sets each property to start + (end - start) * factor. Tweens are stored in a global group by default, but custom groups allow separate update loops. Chaining is implemented by starting the next tween's clock when the current one completes.

Self-Hosting & Configuration

  • Install via npm under the @tweenjs/tween.js scope
  • Call TWEEN.update() inside your animation loop (requestAnimationFrame or a renderer loop)
  • Use new TWEEN.Group() to isolate tweens from the global group
  • Set .repeat(Infinity).yoyo(true) for ping-pong looping animations
  • Pass a custom time argument to update() for deterministic playback

Key Features

  • 30+ easing functions covering all standard curves plus elastic and bounce
  • Chainable API: .to().easing().delay().repeat().yoyo().onUpdate().start()
  • Tween groups for managing independent animation timelines
  • TypeScript definitions included in the package
  • Tiny footprint (~4 KB minified) with zero dependencies

Comparison with Similar Tools

  • anime.js — animates DOM/CSS/SVG directly; Tween.js operates on plain objects, ideal for WebGL and Three.js
  • GSAP — feature-rich timeline engine; Tween.js is minimal and focused on numeric interpolation
  • mo.js — shape and burst primitives; Tween.js is a lower-level value interpolation engine
  • D3 transitions — tied to D3 selections; Tween.js is standalone and framework-independent

FAQ

Q: How do I use Tween.js with Three.js? A: Tween the object's position, rotation, or scale properties and call TWEEN.update() in your render loop.

Q: Can I tween colors? A: Tween.js interpolates numbers. Decompose colors into RGB components, tween each, and reconstruct the color in onUpdate.

Q: What happens if I start a new tween on the same object? A: Both tweens run independently. Call .stop() on the previous tween first to avoid conflicts.

Q: Is Tween.js suitable for DOM animations? A: It can drive DOM animations via onUpdate, but libraries like anime.js or GSAP handle DOM specifics (units, transforms) more conveniently.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产