Skip to content

Instantly share code, notes, and snippets.

@fi-tomek-augustyn
Created March 8, 2012 08:25
Show Gist options
  • Save fi-tomek-augustyn/1999647 to your computer and use it in GitHub Desktop.
Save fi-tomek-augustyn/1999647 to your computer and use it in GitHub Desktop.
Tween.js example
function init() {
// Create and populate the Array of Objects
for (var i = 0; i < numPoints; i++) {
var point = addDOMPoint(i);
pointsY[i] = {
// index
i: i,
x: i * xSpacing,
y: 400,
// DOM reference, used in update();
point: point
}
}
}
// Randomise now Array of Objects with changed property
function randomise() {
for (var i = 0; i < numPoints; i++) {
newPointsY[i] = {
y: Math.random() * 400
}
}
}
function tween() {
// Execute separate tweens for each Object
for (var i = 0; i < numPoints; i++) {
var tween = new TWEEN.Tween(pointsY[i])
.to(newPointsY[i], 500)
.easing(TWEEN.Easing.Cubic.EaseInOut)
.onUpdate(update)
.delay(i * 20)
.start();
}
}
// step function
function update() {
// some DOM manipulation
setPointCSS(pointsY[this.i].point, pointsY[this.i].x, pointsY[this.i].y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment