Permalink
Browse files

make Animation more intuitive; expose easing method, rate, and time p…

…roperties
  • Loading branch information...
1 parent ef2ab30 commit 09b7c9953609c365a440d506e9cc19e30836d156 @matzko committed Apr 3, 2011
Showing with 29 additions and 13 deletions.
  1. +28 −12 client-files/js/filosofo-js.dev.js
  2. +1 −1 client-files/js/filosofo-js.js
@@ -261,6 +261,15 @@ var FilosofoJS = function(scope) {
var i = lerp(start, end, value * value * ( 3 - 2 * value ));
return i;
},
+
+ /*
+ berp = function( start, end, value ) {
+ value = 0 > value ? 0 : value;
+ value = 1 < value ? 1 : value;
+ value = ( Math.sin( value * Math.PI * (0.2 + 2.5 * value * value * value)) * Math.pow(1 - value, 2.2) + value) * (1 + (1.2 * (1 - value)));
+ return start + (end - start) * value;
+ },
+ /**/
inProgress = false,
/**
@@ -317,7 +326,7 @@ var FilosofoJS = function(scope) {
}
},
- Animation = function(diff, callback) {
+ Animation = function(diff, callback) {
return {
animate:function() {
if ( this.inProgress )
@@ -326,9 +335,7 @@ var FilosofoJS = function(scope) {
callback = callback || function() {};
- var rate = 20,
- time = 500,
- steps = time / rate,
+ var steps = this.time / this.rate,
i,
last = false,
state,
@@ -337,7 +344,7 @@ var FilosofoJS = function(scope) {
for ( i = 0; i < steps; i++ ) {
last = ( i + 1 ) < steps ? false : true;
- state = 0 < diff ? hermite(0, 1, (i / steps)) * diff : hermite(1, 0, (i / steps)) * diff;
+ state = this.easing(0, 1, (i / steps)) * diff;
(function(cb) {
var k = i,
l = last,
@@ -346,10 +353,13 @@ var FilosofoJS = function(scope) {
if ( l )
that.inProgress = false;
cb.apply(that, [curDiff, l]);
- }, k * rate);
+ }, k * that.rate);
})(callback);
}
- }
+ },
+ easing:hermite,
+ rate:20,
+ time:500
}
},
@@ -369,25 +379,31 @@ var FilosofoJS = function(scope) {
var fadeCallback = function(curDiff, isLast) {
- var o = 100 + curDiff * dir;
+ // var o = 100 + curDiff * dir;
+ var o = -1 === dir ? 100 + curDiff : curDiff;
obj.style.opacity = o / 100;
obj.style.filter = 'alpha(opacity=' + o + ')';
if ( isLast ) {
callback.call(obj);
- if ( -1 === dir )
+ if ( -1 === dir ) {
+ obj.style.opacity = 0;
+ obj.style.filter = 'alpha(opacity=0)';
obj.style.display = 'none';
- else
+ } else {
+ obj.style.opacity = 1;
+ obj.style.filter = 'alpha(opacity=100)';
obj.style.display = 'block';
+ }
}
},
animator;
if ( obj ) {
if ( -1 === dir ) {
- animator = new Animation(100, fadeCallback),
+ animator = new Animation(-100, fadeCallback),
animator.animate();
} else {
- animator = new Animation(-100, fadeCallback);
+ animator = new Animation(100, fadeCallback);
animator.animate();
}
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 09b7c99

Please sign in to comment.