Comparing version 0.1.0 to 0.2.0
76
index.js
@@ -6,2 +6,14 @@ 'use strict'; | ||
var defaultGetter = function(object, property) { | ||
return object[property]; | ||
} | ||
var defaultSetter = function(object, property, value) { | ||
object[property] = value; | ||
} | ||
var linearEasing = function(t) { | ||
return t; | ||
} | ||
var defaultOptions = { | ||
@@ -12,3 +24,6 @@ object: null, // must provide | ||
props: {}, | ||
cancelable: true | ||
cancelable: true, | ||
getter: defaultGetter, | ||
setter: defaultSetter, | ||
easing: linearEasing | ||
//onDone | ||
@@ -30,5 +45,14 @@ //onCancel | ||
for (var key in this.props) { | ||
if (this.object.hasOwnProperty(key)) { | ||
this.animationStartValues[key] = this.object[key]; | ||
var propVal = this.props[key], getter; | ||
if (typeof propVal !== "object" || propVal === null || Array.isArray(propVal)) { | ||
this.props[key] = { | ||
value: this.props[key] | ||
}; | ||
getter = this.getter; | ||
} | ||
else { | ||
getter = propVal.getter || this.getter; | ||
} | ||
this.animationStartValues[key] = getter(this.object, key); | ||
} | ||
@@ -43,26 +67,30 @@ } | ||
t = 1; | ||
var obj = this.object; | ||
for (var key in this.props) { | ||
if (obj.hasOwnProperty(key)) { | ||
var value = this.props[key], startValue; | ||
if (Array.isArray(value)) { | ||
// Specified step values | ||
var nValues = value.length; | ||
var index = Math.floor(t * nValues); | ||
if (index >= nValues) | ||
index = nValues-1; | ||
obj[key] = value[index]; | ||
} | ||
else if (typeof value === "function") | ||
{ | ||
startValue = this.animationStartValues[key]; | ||
obj[key] = value(t, startValue); | ||
} | ||
else if (Number.isFinite(value)) | ||
{ | ||
startValue = this.animationStartValues[key]; | ||
var newValue = startValue + t*(value - startValue); | ||
obj[key] = newValue; | ||
} | ||
var spec = this.props[key], | ||
value = spec.value, | ||
setter = spec.setter || this.setter, | ||
easing = spec.easing|| this.easing, | ||
teased = easing(t), | ||
startValue; | ||
if (Array.isArray(value)) { | ||
// Specified step values | ||
var nValues = value.length; | ||
var index = Math.floor(teased * nValues); | ||
if (index >= nValues) | ||
index = nValues-1; | ||
setter(obj, key, value[index]); | ||
} | ||
else if (typeof value === "function") | ||
{ | ||
startValue = this.animationStartValues[key]; | ||
setter(obj, key, value(teased, startValue)); | ||
} | ||
else if (Number.isFinite(value)) | ||
{ | ||
startValue = this.animationStartValues[key]; | ||
var newValue = startValue + teased * (value - startValue); | ||
setter(obj, key, newValue); | ||
} | ||
} | ||
@@ -69,0 +97,0 @@ if (t === 1) { |
{ | ||
"name": "anymation", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Simple & easy animation/tweener", | ||
@@ -23,2 +23,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"eases": "^1.0.8", | ||
"extend": "^3.0.0", | ||
@@ -25,0 +26,0 @@ "right-now": "^1.0.0" |
5137
94
3
+ Addedeases@^1.0.8
+ Addedeases@1.0.8(transitive)