Created
November 28, 2014 18:49
-
-
Save willbailey/a5464d9e12912e04a759 to your computer and use it in GitHub Desktop.
animation.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// A list of layers with initial values | |
var layers = [ | |
{ | |
name: 'red-square', | |
width: 200, | |
height: 200, | |
x: 0, | |
y: 0, | |
background: '#ff0000' | |
} | |
]; | |
// Each transition has its own spring, but you could easily extend | |
// this so a transition declared a spring name and let the animation | |
// class manage sharing them. | |
var transitions = [ | |
{ | |
name: 'slide', | |
layers: ['red-square'], | |
start: 0, | |
end: 200, | |
tension: 40, | |
friction: 7, | |
fields: ['x', 'y'] | |
}, | |
{ | |
name: 'rotate', | |
layers: ['red-square'], | |
start: 0, | |
end: 45, | |
tension: 40, | |
friction: 7, | |
fields: ['rot'] | |
} | |
]; | |
document.addEventListener('DOMContentLoaded', function() { | |
// create an Animation. | |
var animation = window.animation = new Animation(layers, transitions); | |
// Not sure exactly how trigger the animation to start should work. I keep | |
// a map of them so I can just directly control them here. | |
var transition = animation.getTransition('slide'); | |
transition.go(1); | |
var transition2 = animation.getTransition('rotate'); | |
transition2.go(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment