主题:[原创]救救一个垂死的人吧
zhaicunwei
[专家分:0] 发布于 2007-10-08 15:37:00
兄弟我想让一个图层始终停留在窗体的中间位置(随着窗体的滑动时,也是同样停留在当前窗体的中间位置),跪谢!!!很急!!
回复列表 (共1个回复)
沙发
jzyray [专家分:20610] 发布于 2007-10-09 22:48:00
可以在resize和scroll事件中调用将层移动到某一位置的代码
具体代码可以参见cross-browser的xSlideTo函数:
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();
}
}
我来回复