mapbox-gl
Version:
A WebGL interactive maps library
31 lines (25 loc) • 733 B
JavaScript
;
module.exports = AnimationLoop;
function AnimationLoop() {
this.n = 0;
this.times = [];
}
// Are all animations done?
AnimationLoop.prototype.stopped = function() {
this.times = this.times.filter(function(t) {
return t.time >= (new Date()).getTime();
});
return !this.times.length;
};
// Add a new animation that will run t milliseconds
// Returns an id that can be used to cancel it layer
AnimationLoop.prototype.set = function(t) {
this.times.push({ id: this.n, time: t + (new Date()).getTime() });
return this.n++;
};
// Cancel an animation
AnimationLoop.prototype.cancel = function(n) {
this.times = this.times.filter(function(t) {
return t.id !== n;
});
};