Download the X Distribution File.
xSlideTo(ele, iX, iY, iTime)
// xSlideTo r3, Copyright 2001-2007 Michael Foster (Cross-Browser.com) // Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL function xSlideTo(e, x, y, uTime) { if (!(e=xGetElementById(e))) return; if (!e.timeout) e.timeout = 25; e.xTarget = x; e.yTarget = y; e.slideTime = uTime; e.stop = false; e.yA = e.yTarget - xTop(e); e.xA = e.xTarget - xLeft(e); // A = distance if (e.slideLinear) e.B = 1/e.slideTime; else e.B = Math.PI / (2 * e.slideTime); // B = period e.yD = xTop(e); e.xD = xLeft(e); // D = initial position var d = new Date(); e.C = d.getTime(); if (!e.moving) _xSlideTo(e); } function _xSlideTo(e) { if (!(e=xGetElementById(e))) return; var now, s, t, newY, newX; now = new Date(); t = now.getTime() - e.C; if (e.stop) { e.moving = false; } else if (t < e.slideTime) { setTimeout("_xSlideTo('"+e.id+"')", e.timeout); s = e.B * t; if (!e.slideLinear) s = Math.sin(s); // if (e.slideLinear) s = e.B * t; // else s = Math.sin(e.B * t); newX = Math.round(e.xA * s + e.xD); newY = Math.round(e.yA * s + e.yD); xMoveTo(e, newX, newY); e.moving = true; } else { xMoveTo(e, e.xTarget, e.yTarget); e.moving = false; if (e.onslideend) e.onslideend(); } }
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.