mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Keep the native animation loop running as long as there are unprocessed callbacks.
This commit is contained in:
parent
a6c175c82c
commit
c797f2f0ad
1 changed files with 12 additions and 2 deletions
|
@ -106,7 +106,6 @@ DomEvent.requestAnimationFrame = new function() {
|
|||
});
|
||||
|
||||
function handleCallbacks() {
|
||||
requested = false;
|
||||
// Checks all installed callbacks for element visibility and
|
||||
// execute if needed.
|
||||
for (var i = callbacks.length - 1; i >= 0; i--) {
|
||||
|
@ -115,11 +114,22 @@ DomEvent.requestAnimationFrame = new function() {
|
|||
el = entry[1];
|
||||
if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true'
|
||||
|| focused) && DomElement.isInView(el)) {
|
||||
// Handle callback and remove it from callbacks list.
|
||||
// Only remove from the list once the callback was called. This
|
||||
// could take a long time based on visibility. But this way we
|
||||
// are sure to keep the animation loop running.
|
||||
callbacks.splice(i, 1);
|
||||
func();
|
||||
}
|
||||
}
|
||||
if (nativeRequest) {
|
||||
if (callbacks.length) {
|
||||
// If we haven't processed all callbacks yet, we need to keep
|
||||
// the loop running, as otherwise it would die off.
|
||||
nativeRequest(handleCallbacks);
|
||||
} else {
|
||||
requested = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return function(callback, element) {
|
||||
|
|
Loading…
Reference in a new issue