Download the X Distribution File.
obj = new xAnimation(res);
// xAnimation r5, Copyright 2006-2010 Michael Foster (Cross-Browser.com) // Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL function xAnimation(r) { this.res = r || 10; } // Initialize an array of n axis objects. xAnimation.prototype.axes = function(n) { var j, i = this; if (!i.a || i.a.length != n) { i.a = []; for (j = 0; j < n; ++j) { i.a[j] = { i:0, t:0, d:0, v:0 }; // initial value, target value, displacement, instantaneous value } } }; // The caller must set the axes' initial and target values before calling init. xAnimation.prototype.init = function(e,t,or,ot,oe,at,b) { var ai, i = this; i.e = xGetElementById(e); i.t = t; i.or = or; // onRun i.ot = ot; // onTarget i.oe = oe; // onEnd i.at = at || 0; // acceleration type i.v = xAnimation.vf[i.at]; i.qc = 1 + (b || 0); // quarter-cycles i.fq = 1 / i.t; // frequency if (i.at > 0 && i.at < 4) { i.fq *= i.qc * Math.PI; if (i.at == 1 || i.at == 2) { i.fq /= 2; } } // displacements for (ai = 0; ai < i.a.length; ++ai) { i.a[ai].d = i.a[ai].t - i.a[ai].i; } }; xAnimation.prototype.run = function(r) { var ai, qcm2, rep, i = this; if (!r) { i.t1 = new Date().getTime(); } if (!i.tmr) i.tmr = setInterval( function() { i.et = new Date().getTime() - i.t1; // elapsed time if (i.et < i.t) { // instantaneous values i.f = i.v(i.et * i.fq); for (ai = 0; ai < i.a.length; ++ai) { i.a[ai].v = i.a[ai].d * i.f + i.a[ai].i; } i.or(i); // call onRun } else { // target time reached clearInterval(i.tmr); i.tmr = null; qcm2 = i.qc % 2; for (ai = 0; ai < i.a.length; ++ai) { if (qcm2) { i.a[ai].v = i.a[ai].t; } else { i.a[ai].v = i.a[ai].i; } } i.ot(i); // call onTarget // handle onEnd rep = false; if (typeof i.oe == 'function') { rep = i.oe(i); } else if (typeof i.oe == 'string') { rep = eval(i.oe); } if (rep) { i.resume(1); } } }, i.res ); }; xAnimation.prototype.pause = function() { clearInterval(this.tmr); this.tmr = null; }; xAnimation.prototype.resume = function(fs) { if (typeof this.tmr != 'undefined' && !this.tmr) { this.t1 = new Date().getTime(); if (!fs) {this.t1 -= this.et;} this.run(!fs); } }; // Static array of velocity functions xAnimation.vf = [ function(r){return r;}, function(r){return Math.abs(Math.sin(r));}, function(r){return 1-Math.abs(Math.cos(r));}, function(r){return (1-Math.cos(r))/2;}, function(r) {return (1.0 - Math.exp(-r * 6));} ]; // end xAnimation
xanimation - Start page of all xAnimation demos.
init 0: fq = 1/t 1&2: fq = 1/t * qc * PI/2 3: fq = 1/t * qc * PI run function(r){return r;}, function(r){return Math.abs(Math.sin(r));}, function(r){return 1-Math.abs(Math.cos(r));}, function(r){return (1-Math.cos(r))/2;}, function(r) {return (1.0 - Math.exp(-r * 6));} // r4 Here's a graph of the above velocity functions: http://cross-browser.com/images/animation_vf_graph2.gif
By your use of X and/or CBE and/or any Javascript from this site you consent to the GNU LGPL - please read it. If you have any questions about the license, read the FAQ and/or come to the forums.
Forum support is available at the X Library Support Forums.
Cross-Browser.com is the home of X - a cross-browser Javascript library, and many demos, applications, articles and documentation.
If you are using X, XC or anything from this site, show off your work by posting a link in the X Showcase forum.