animated array

by meo

JavaScript

var AnimateArray = function( arr,callback,speed ){
    this.arr = arr;
    this.speed = Math.round( speed/arr.length ) || 3000;
    this.callback = callback || function(){};
    
};

AnimateArray.prototype.easingFunction = function( speed,i ){
    return speed / i; 
};

function customEasing( position ) {
    return position * position;
}
    
AnimateArray.prototype._newTimer = function( i ){
    
    var timer, that = this;
    
    if( i < that.arr.length  ) {
        timer = setTimeout(function(){
            
            that.callback( that.arr[ i ],i );
            that._newTimer( i + 1 );
            
        },that.easingFunction( that.speed, i) );
    }
}
    
AnimateArray.prototype.start = function( startPosition ){
    this._newTimer( startPosition || 0 );
};

var $b = $("body");

var aa = new AnimateArray(["01","02","03","04","05","06","07","08","09","10","11","12","13"],function(d,i){ $b.text(d + " " + i ) },6600);

aa.start();
 
/*                                                                                               
var animator = new Animator(); 
Animator.addEasingFunction( 'ease-out', f );                                                                                                            
animator.animateNumber( 8, 15, 300, 'ease-out' );
animator.stop();
animator.addCallback(f);  */