add Artplayer.USE_RAF

This commit is contained in:
Harvey Zack committed 2023-08-26 00:03:26 +08:00
1 parent 6fc1532ada
commit 9ba838aa52
10 files changed
+105 -11

No files matched your search

+2
View File
@@ -6,6 +6,7 @@ import resizeInit from './resizeInit';
import gestureInit from './gestureInit';
import viewInit from './viewInit';
import documentInit from './documentInit';
import updateInit from './updateInit';
export default class Events {
constructor(art) {
@@ -21,6 +22,7 @@ export default class Events {
gestureInit(art, this);
viewInit(art, this);
documentInit(art, this);
updateInit(art, this);
}
proxy(target, name, callback, option = {}) {
@@ -0,0 +1,19 @@
export default function updateInit(art) {
if (art.constructor.USE_RAF) {
let timer = null;
(function update() {
if (art.playing) {
art.emit('raf');
}
if (!art.isDestroy) {
timer = requestAnimationFrame(update);
}
})();
art.on('destroy', () => {
cancelAnimationFrame(timer);
});
}
}