Fix mina frame loop exit on resume (#499)

Invoke frame function from resume to restart animation loop when it has
previously exited after running out of animations. Add checks to frame
function and move handling of animation frame requests internally to
prevent simultaneous requests / loops.

Fixes adobe-webplatform/Snap.svg#496
master
Thomas Brierley 2017-01-31 23:50:07 +00:00 committed by Dmitry Baranovskiy
parent 768ddb1b77
commit 230396fd68
1 changed files with 16 additions and 4 deletions

View File

@ -19,8 +19,10 @@ var mina = (function (eve) {
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
setTimeout(callback, 16);
setTimeout(callback, 16, new Date().getTime());
return true;
},
requestID,
isArray = Array.isArray || function (a) {
return a instanceof Array ||
Object.prototype.toString.call(a) == "[object Array]";
@ -94,6 +96,7 @@ var mina = (function (eve) {
a.b = a.get() - a.pdif;
delete a.pdif;
animations[a.id] = a;
frame();
},
update = function () {
var a = this,
@ -109,7 +112,16 @@ var mina = (function (eve) {
}
a.set(res);
},
frame = function () {
frame = function (timeStamp) {
// Manual invokation?
if (!timeStamp) {
// Frame loop stopped?
if (!requestID) {
// Start frame loop...
requestID = requestAnimFrame(frame);
}
return;
}
var len = 0;
for (var i in animations) if (animations.hasOwnProperty(i)) {
var a = animations[i],
@ -129,7 +141,7 @@ var mina = (function (eve) {
}
a.update();
}
len && requestAnimFrame(frame);
requestID = len ? requestAnimFrame(frame) : false;
},
/*\
* mina
@ -193,7 +205,7 @@ var mina = (function (eve) {
break;
}
}
len == 1 && requestAnimFrame(frame);
len == 1 && frame();
return anim;
};
/*\