X Library Viewer

Download the X Distribution File.

X Index

Animation

xAniLine, xAnimation.arc, xAnimation.corner, xAnimation.css, xAnimation.imgSize, xAnimation.line, xAnimation.opacity, xAnimation.para, xAnimation.rgb, xAnimation.rgbByClass, xAnimation.scroll, xAnimation.size, xAnimation, xAniOpacity, xAniRgb, xAniWH, xAniXY, xEllipse, xParaEq, xSequence, xSlideCornerTo, xSlideTo, xWinScrollTo.

DOM

xFirstChild, xGetElementById, xGetElementsByAttribute, xGetElementsByClassName, xGetElementsByTagName, xLoadLink, xLoadScript, xNextSib, xParent, xParentN, xPrevSib, xSmartLoad, xSmartLoad2, xSmartLoadScript.

Debug

xConsole, xEditable, xName, xParentChain, xSetIETitle.

Event

xAddEventListener, xDisableDrag, xDisableDrop, xEnableDrag, xEnableDrag2, xEnableDrop, xEvent, xHttpRequest, xPreventDefault, xRemoveEventListener, xStopPropagation.

Image

xImgAsyncWait, xImgRollSetup, xTriStateImage.

Iteration

xEach, xEachE, xEachN, xEachUntilReturn, xTimes, xWalkToFirst, xWalkToLast, xWalkTree, xWalkTree2, xWalkTree3, xWalkTreeRev, xWalkUL.

Misc

xCookie, xDef, xDeg, xGetURLArguments, xLibrary, xLinearScale, xNum, xRad, xRound, xStr.

Position

xCardinalPosition, xCen, xCenter, xGetEleAtPoint, xHasPoint, xIntersection, xLeft, xMoveTo, xOffset, xPageX, xPageY, xScrollLeft, xScrollTop, xTop.

Size

xClip, xColEqualizer, xDocSize, xHeight, xResizeTo, xWidth.

String

xCamelize, xCapitalize, xHex, xPad, xParseColor, xRgbToHex, xStrEndsWith, xStrReplaceEnd, xStrStartsWith, xTrim.

Style

xAddClass, xDisplay, xFindAfterByClassName, xFindBeforeByClassName, xGetComputedStyle, xGetCSSRules, xGetStyleSheetFromLink, xHasClass, xHasStyleSelector, xHasStyleSheets, xInsertRule, xOpacity, xRemoveClass, xStyle, xTagStyle, xToggleClass, xTraverseDocumentStyleSheets, xTraverseStyleSheet.

Table

xTable, xTableCellVisibility, xTableColDisplay, xTableCursor, xTableCursor2, xTableHeaderFixed, xTableIterate, xTableRowDisplay, xTableSync.

UI

xBar, xCollapsible, xDialog, xFenster, xFenster2, xMenu1, xMenu1A, xMenu1B, xMenu5, xMenu6, xModalDialog, xPopup, xSelect, xSplitter, xTabPanelGroup, xTextArea, xTooltipGroup.

Window

xClientHeight, xClientWidth, xWinClass, xWindow, xWinOpen.

xAnimation

Description

Using xAnimation is easy. Create an xAnimation object and call one of the animation methods. You can then use the pause/resume methods. The init/run methods and the xAnimation properties are documented here to help you write your own animation methods. xAnimation provides an animation "engine" which supports up to three axes of animation, multiple acceleration types and an onEnd handler. The onEnd handler can return true to cause the animation to repeat. It supports a bounce-back feature. Acceleration is implemented as an array of functions so it is easy to add custom acceleration types.

Syntax

obj = new xAnimation(res);

Parameters

resTimer resolution in milliseconds (unsigned integer). Default is 10. Frames-per-sec = 1000/res. Objects can be created before onload. Animation methods should not be called until after onload if animating an Element.

Source

Default.

// xAnimation r4, Copyright 2006-2009 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;
}
xAnimation.prototype.init = function(e,t,or,ot,oe,a,b)
{
  var i = this;
  i.e = xGetElementById(e);
  i.t = t;
  i.or = or; // onRun
  i.ot = ot; // onTarget
  i.oe = oe; // onEnd
  i.a = a || 0; // acceleration type
  i.v = xAnimation.vf[i.a];
  i.qc = 1 + (b || 0); // quarter-cycles
  i.fq = 1 / i.t; // frequency
//  if (i.a) {              // r4
  if (i.a > 0 && i.a < 4) { // r4
    i.fq *= i.qc * Math.PI;
    if (i.a == 1 || i.a == 2) { i.fq /= 2; }
  }
//  else { i.qc = 1; } // r4
  // displacements
  i.xd = i.x2 - i.x1;
  i.yd = i.y2 - i.y1;
  i.zd = i.z2 - i.z1;
};
xAnimation.prototype.run = function(r)
{
  var i = this;
  if (!r) { i.t1 = new Date().getTime(); }
  if (!i.tmr) i.tmr = setInterval(
    function() {
      i.et = new Date().getTime() - i.t1;
      if (i.et < i.t) {
        i.f = i.v(i.et * i.fq);
        i.x = i.xd * i.f + i.x1;
        i.y = i.yd * i.f + i.y1;
        i.z = i.zd * i.f + i.z1;
        i.or(i);
      }
      else { // target time reached
        clearInterval(i.tmr);
        i.tmr = null;
        if (i.qc % 2) {
          i.x = i.x2;
          i.y = i.y2;
          i.z = i.z2;
        }
        else {
          i.x = i.x1;
          i.y = i.y1;
          i.z = i.z1;
        }
        i.ot(i);
        var 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.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));} // r4
];
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);
  }
};

Dependencies

xGetElementById

Demos

xanimation.html - Start page of all xAnimation demos.

Notes

27Apr07 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

Revisions

4: 25Oct09EricJ has submitted an awesome velocity function. It is a 'decay' function. Thanks very much, Eric! See http://cross-browser.com/forums/viewtopic.php?id=667
3: 27Apr07Alexander has submitted a brilliant new velocity function. It is a 'combination' of accel types 1 and 2. Thanks very much, Alexander!
2: 15Apr07xAnimation object re-implemented.
1: 25Sep06Initial release.

License

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.

Tech Support

Forum support is available at the X Library Support Forums.

About Cross-Browser.com

Cross-Browser.com is the home of X - a cross-browser Javascript library, and many demos, applications, articles and documentation.

Search

Cross-Browser.com

World Wide Web

User Projects

If you are using X, XC or anything from this site, show off your work by posting a link in the X Showcase forum.