I've got several looping animations (up/down) which are defined by the following functions.
Looping interval
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);
}
Function 1 (upwards)
function unpeekTile() {
var peekAnimation = WinJS.UI.Animation.createPeekAnimation([tile1, tile2]);
tile1.style.top = "0px";
tile2.style.top = "0px";
peekAnimation.execute();
}
Function 2 (downwards)
function peekTile() {
var peekAnimation = WinJS.UI.Animation.createPeekAnimation([tile1, tile2]);
tile1.style.top = "-120px";
tile2.style.top = "-120px";
peekAnimation.execute();
}
Start
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);
The animations now start at 1000 (interval time) + 0/500/2000 (setTimeout), but I'd like them to start in 0, 500 and 2000 millis. Can anybody help?