我有几个循环动画(上/下),它们是由以下函数定义的。Interval/setTimeout起点
循环间隔
function Cycler(f) {
if (!(this instanceof Cycler)) {
// Force new
return new Cycler(arguments);
}
// Unbox args
if (f instanceof Function) {
this.fns = Array.prototype.slice.call(arguments);
} else if (f && f.length) {
this.fns = Array.prototype.slice.call(f);
} else {
throw new Error('Invalid arguments supplied to Cycler constructor.');
}
this.pos = 0;
}
Cycler.prototype.start = function (interval) {
var that = this;
interval = interval || 1000;
this.intervalId = setInterval(function() {
that.fns[that.pos++]();
that.pos %= that.fns.length;
}, interval);
}
功能1(向上)
function unpeekTile() {
var peekAnimation = WinJS.UI.Animation.createPeekAnimation([tile1, tile2]);
tile1.style.top = "0px";
tile2.style.top = "0px";
peekAnimation.execute();
}
功能2(向下)
function peekTile() {
var peekAnimation = WinJS.UI.Animation.createPeekAnimation([tile1, tile2]);
tile1.style.top = "-120px";
tile2.style.top = "-120px";
peekAnimation.execute();
}
开始
function c() { Cycler(peekTile, unpeekTile).start(); }
setTimeout(c, 0);
function c2() { Cycler(peekTile2, unpeekTile2).start(); }
setTimeout(c2, 500);
function c3() { Cycler(peekTile3, unpeekTile3).start(); }
setTimeout(c3, 2000);
动画现在开始于1000(间隔时间)+ 0/500/2000(setTimeout),但我希望它们以0,500和2000毫秒开始。任何人都可以帮忙吗?
我认为*会将'int_callback'放入全局命名空间。可能想要在那里抛出一个'var'。 – Dancrumb 2012-07-07 23:10:27
我已经做了 - 见评论(第2行) – Utkanos 2012-07-07 23:15:11
非常感谢 - 为我解决了!只需稍作更改:int_callback var必须分别声明:var that = this; var int_callback; – Betsy 2012-07-08 07:04:08